How do I paste the name of the alternate (previously edited) file into the buffer?
"#p
The # register holds the name of the alternate file — the file you were editing just before the current one.
Search Vim Tricks
Searching..."#p
The # register holds the name of the alternate file — the file you were editing just before the current one.
50%
Prefixing the % command with a count jumps the cursor to that percentage through the file.
/pattern\C
Appending \C anywhere in a search pattern forces the entire search to be case-sensitive, regardless of whether ignorecase or smartcase is set.
search #search #case-sensitive #ignorecase #smartcase #normal-mode
:set grepprg={cmd} grepformat={fmt}
Vim's :grep command delegates to an external tool defined by grepprg, then parses the output according to grepformat to populate the quickfix list.
:spellrepall
After correcting a misspelled word with z= (or 1z= for the first suggestion), run :spellrepall to apply that same correction to every other occurrence of the id
:set foldopen
The foldopen option lets you specify exactly which cursor movements and commands will automatically open a closed fold.
<C-u> in insert mode
Pressing while in insert mode deletes all characters entered since you last entered insert mode on the current line.
\@= and \@<=
Vim's regex engine supports zero-width lookahead and lookbehind assertions — \@= and \@<= — which let you match text based on surrounding context without in
fnameescape(filename)
When building Vim Ex commands dynamically, filenames with spaces, , %, #, [, or other special characters will be misinterpreted — the space looks like an argu
globpath(&rtp, 'pattern')
globpath() is a Vimscript function that searches all directories in a given path list for files matching a glob pattern.
:echohl WarningMsg | echo "message" | echohl None
:echohl sets the highlight group applied to subsequent :echo and :echom output.
expand('%:p:h:t')
Vim's filename modifiers can be chained to transform paths step by step.
gw
The gw operator reformats text to fit within textwidth, just like gq — but with one key difference: gw leaves the cursor in its original position after format
:set display=lastline
By default, when the last visible line of a window is too long to fit on screen, Vim shows @@@ in its place — hiding the content entirely.
autocmd ++once
The ++once flag, added in Vim 8.
:'<,'>norm! A;
The :normal Ex command lets you execute any Normal mode keystrokes on a range of lines simultaneously, turning a single-line operation into a multi-line batch e
editing #editing #normal-mode #ex-commands #visual-mode #text-manipulation
<C-f>
While typing in Vim's command line (after pressing :), pressing opens the command-line window with your current, unfinished command already filled in.
<C-w>g]
g] splits the window and then runs :tselect for the identifier under the cursor, displaying a numbered list of all matching tags so you can pick the exact defin
v:register
When writing custom mappings or operator functions, v:register gives you the register name that the user prefixed the mapping with.
:set formatprg={program}
Vim's gq operator normally reflows text to fit textwidth, but by setting formatprg you can delegate formatting to any external tool — a language formatter, a