How do I replace a visual selection with yanked text in Vim?
p (in visual mode)
In visual mode, pressing p replaces the selected text with the contents of the default register.
p (in visual mode)
In visual mode, pressing p replaces the selected text with the contents of the default register.
]m / [m
Vim's ]m and [m motions navigate between method and function boundaries in curly-brace languages like C, Java, JavaScript, and Go.
\v
Vim's default regex mode ("magic") requires backslashes before many special characters: \(, \ , \+, \{.
{count}<C-a> / {count}<C-x>
While increments and decrements a number by 1, you can prefix either with a count to add or subtract a specific amount.
:set matchpairs+=<:>
By default, the % command jumps between (), {}, and [] pairs.
config #navigation #config #matchpairs #editing #normal-mode
<C-o>zz
When you are typing in insert mode and the cursor drifts near the top or bottom of the screen, you normally have to press , then zz, then i or a to continue edi
v{motion}<C-g>
Vim has a lesser-known select mode that behaves like selection in typical GUI editors: any typed character replaces the selection.
:nnoremap <expr> j (v:count == 0 ? 'gj' : 'j')
Expression mappings use the flag to evaluate a Vimscript expression at the time the key is pressed.
!{motion}{program}
The ! operator in normal mode lets you pipe a range of text through any external program and replace it with the output.
80i-<Esc>
Vim's insert commands accept a count prefix that repeats everything you type.
gp
The standard p command pastes text after the cursor but leaves the cursor at the beginning of the pasted text.
[{ / ]}
When editing code inside a deeply nested block, [{ jumps backward to the unmatched { that encloses the current position, and ]} jumps forward to its matching }.
v / V / <C-v> (while in visual mode)
When you are already in visual mode and realize you need a different selection type, you do not have to exit and re-enter.
]m and [m
The ]m and [m motions let you jump forward and backward between the start of method or function definitions.
qqqqqq{edits}@qq
A recursive macro calls itself at the end of its sequence, creating a loop that automatically repeats until a motion or command fails (such as hitting the last
<C-\><C-n>
While works to leave insert or visual mode, it does not work in every situation — particularly in terminal mode (:terminal), where is consumed by the running
zf{motion}
Vim supports several fold methods, but manual folding with zf gives you precise control over exactly which lines to collapse.
g<C-g>
While shows basic file info (filename, line count, position), g provides a much more detailed statistical breakdown of your file or visual selection.
:keepjumps
When writing scripts or running commands that move the cursor (like :g, :s, or :normal), Vim normally adds each cursor position to the jump list.
:set operatorfunc=MyFunc<CR>g@
Vim lets you define custom operators that behave like built-in ones (d, c, y) — they wait for a motion or text object, then act on the selected region.