How do I move a line or range of lines to a different location in the file?
:m {address}
How it works The :m command (short for :move) moves one or more lines to after the specified address.
2125 results for "i' a'"
:m {address}
How it works The :m command (short for :move) moves one or more lines to after the specified address.
:<C-u>MyCommand<CR>
When writing nnoremap or vnoremap mappings that call Ex commands, Vim may silently prepend a count or a visual range (') to your command before it runs.
<C-o> (insert mode)
Pressing while in insert mode lets you execute exactly one normal mode command and then automatically returns you to insert mode.
:set foldcolumn=1
Setting foldcolumn to a non-zero value adds a narrow column on the left side of each window that visually represents the fold structure of your file.
:lua {code}
Neovim's :lua command lets you run arbitrary Lua code inline from the command line.
command-line #command-line #lua #neovim #vimscript #advanced
:'<,'>right {width}
The :right Ex command right-aligns lines within a given column width by padding them with spaces on the left.
visual-mode #visual-mode #formatting #ex-commands #alignment
%:r
The %:r expression expands to the current filename with its extension removed (the "root" of the filename).
/pattern/e+2
Vim's search command supports an offset suffix that controls where the cursor lands after a match.
qqgUiwjq2@q
Macros are strongest when the edit pattern is stable but too awkward for a one-liner substitute.
gr{char}
The gr{char} command is Vim's virtual replace variant of r{char}.
zp
Pastes a blockwise register like p, but skips padding lines shorter than the block's right edge with trailing spaces.
:'<,'>norm .
The :'norm .
visual-mode #visual-mode #editing #normal-mode #repeat #dot-operator
zh and zl
When wrap is disabled, long lines extend off-screen.
:'<,'>w filename
How it works Vim's :w command can take a range, and when used with a visual selection, it writes only the selected lines to a file.
:%s/\v(\d+)/\=printf('%04d', submatch(1))/g
When you need stable-width numeric fields, manual edits are slow and error-prone.
command-line #command-line #substitution #regex #refactoring
:%s/\v<(\w)(\w*)>/\u\1\L\2/g
When you need to normalize casing across headings, labels, or generated docs, editing words one by one is tedious.
:g/pattern/m $
The :g (global) command combined with :m (move) lets you collect all lines matching a pattern and relocate them to a specific position in the file.
command-line #ex-commands #editing #global #search #formatting
:xmap
:vmap applies to both visual mode and select mode, which can silently break snippet plugins (like UltiSnips, LuaSnip) that use select mode to position the curso
999@q
Prefixing a macro invocation with a large count like 999@q tells Vim to run register q up to 999 times.
:let @q .= "keys"
The string concatenation assignment :let @q .