How do I run a normal mode command on every line in a range?
:{range}normal {commands}
The :normal command executes normal mode keystrokes from the command line.
command-line #command-line #ex-commands #editing #normal-mode
:{range}normal {commands}
The :normal command executes normal mode keystrokes from the command line.
command-line #command-line #ex-commands #editing #normal-mode
:Vexplore
Vim ships with netrw, a built-in file explorer that requires no plugins.
<C-r><C-w>
When typing a command on the Vim command line, pressing inserts the word currently under the cursor.
"ap, edit, 0"ay$
When a macro has a small mistake, re-recording the entire thing is tedious.
:center
The :center command pads a line with leading spaces so the text is centered within a given width.
]]
The ]] motion jumps forward to the next line that starts with { in the first column, which is typically the beginning of a C-style function or section.
/\(foo\)\@<=bar
Use \@<= for positive lookbehind.
:%s/; /;\r/g
In the replacement part, use \r to insert a newline.
vii with indent-object plugin
The vim-indent-object plugin provides ii (inner indent) and ai (around indent) text objects.
:let @a = 'hello world'
Use :let @a = 'text' to set register a to any string.
set signcolumn=yes
Use set signcolumn=yes to always display the sign column (used by diagnostics, git markers).
require('nvim-autopairs').setup()
nvim-autopairs automatically inserts matching closing brackets, quotes, and tags as you type.
require('oil').setup()
Oil.
nnoremap <leader>b :b#<CR>
Map b to :b# which switches to the alternate buffer.
v'a
Press v for visual mode, then 'a to extend the selection to mark a.
<C-v>jj<C-a>
Select numbers with visual block mode , then press to increment all selected numbers by 1.
"_dP in visual mode
Use "_dP which deletes the selection into the black hole register and pastes before.
<C-v>jjll
Press for visual block mode, then use movement keys to select a rectangle.
:%s/\d\+/\=submatch(0)*2/g
Use \= to evaluate expressions.
<C-v>j$
In visual block mode, press $ to extend each line's selection to its end, even if lines have different lengths.