How do I discard all unsaved changes and reload the file from disk in Vim?
:e!
:e! forces Vim to reload the current file from disk, discarding every unsaved change in the buffer.
buffers-windows #buffers-windows #editing #undo-redo #ex-commands
2277 results for "@a"
:e!
:e! forces Vim to reload the current file from disk, discarding every unsaved change in the buffer.
buffers-windows #buffers-windows #editing #undo-redo #ex-commands
:profile start /tmp/profile.log | profile func *
When Vim feels sluggish during editing (not just at startup), the :profile command lets you measure the execution time of every function call.
[{ and ]}
The [{ motion jumps to the previous unmatched { — the opening brace of the block enclosing your cursor.
<C-r><C-o>"
The {register} sequence in insert mode pastes register contents literally — without triggering auto-indentation, abbreviations, or mappings.
<C-k>
Vim has a built-in digraph system that lets you type special characters using short two-character codes.
:set shiftwidth=0
Setting shiftwidth=0 tells Vim to use the value of tabstop wherever shiftwidth would normally be consulted — for the > and and in insert mode, and auto-indent
:set grepprg=rg\ --vimgrep\ --smart-case
By default, Vim's :grep command calls the system grep.
<C-x><C-n>
triggers keyword completion that searches only the current buffer for matches, scanning forward from the cursor.
<C-g> and <C-t>
While the search prompt is open (with incsearch enabled), pressing advances the cursor to the next match and moves it to the previous match — all without leav
zR and zM
When working with a heavily folded file, manually opening or closing each fold is tedious.
:set splitbelow splitright
How it works By default, Vim opens horizontal splits (:split or :sp) above the current window and vertical splits (:vsplit or :vsp) to the left.
:.+1,.+3d
Vim's Ex command addresses support arithmetic offsets relative to the current line (.
command-line #ex-commands #editing #navigation #command-line
gp
The standard p command pastes text after the cursor but leaves the cursor at the beginning of the pasted text.
:set switchbuf+=uselast
When jumps open the target buffer in an unexpected split, context switching gets expensive.
:profile start profile.log
When Vim feels sluggish, the built-in :profile command lets you measure exactly how much time each script and function consumes.
gw{motion}
The gw operator reformats text just like gq, but leaves the cursor exactly where it started.
autocmd BufWinLeave * mkview
By default, Vim forgets your folds, cursor position, and scroll state every time you close a file.
:lgrep {pattern} {files}
The location list is a per-window counterpart to the global quickfix list.
buffers-windows #buffers-windows #ex-commands #search #navigation
ysiw<em>
The vim-surround plugin makes wrapping text in HTML or XML tags effortless.
* then :%s//new/g
Pressing searches for the word under the cursor, which also loads it into the search register.