How do I split a line by inserting a newline with the substitute command?
:s/,/\r/g
In Vim's substitute command, use \r (not \n) in the replacement to insert a real newline.
:s/,/\r/g
In Vim's substitute command, use \r (not \n) in the replacement to insert a real newline.
:sort /regex/
The :sort /pattern/ command sorts lines by the text that appears after the first match of a pattern, not from the start of each line.
\C
Vim's \C and \c atoms let you override ignorecase and smartcase on a per-pattern basis.
@q
A recursive macro is a macro that calls itself as its last step, causing it to loop automatically until an operation fails (such as reaching the end of the file
:s/pattern//gn
The :s///gn command counts how many times a pattern appears in the file without actually replacing anything.
command-line #search #ex-commands #substitution #command-line
iabbrev
:iabbrev defines insert-mode abbreviations that expand automatically when you type a non-keyword character (space, punctuation, ) after the abbreviation.
:.!{cmd}
:.
:let @/ = 'pattern'
Writing to the @/ register via :let @/ = 'pattern' sets Vim's last-search pattern directly — without performing a search or moving the cursor.
:vimgrep /pattern/ **
:vimgrep /pattern/ searches recursively through all files in the current working directory tree using Vim's own regex engine, populating the quickfix list with
'0
Pressing '0 in normal mode jumps to the exact cursor position in the most recently edited file, even after closing and reopening Vim.
:set opfunc and g@
Vim's operatorfunc option lets you define your own operators — just like the built-in d, y, or c — that accept any motion or text object.
\%l and \%c
Vim's \%l and \%c pattern atoms anchor a search to a particular line number or column, enabling surgical searches and substitutions that standard regex cannot e
%:h
Vim's filename modifiers let you derive path components from the current buffer's filename directly on the command line.
<C-y> and <C-e>
In Insert mode, copies the character at the same column position from the line above the cursor, and copies the character from the line below.
:[range]normal @q
The :[range]normal @q command replays the macro in register q on every line within a given range.
g]
g] is the disambiguation-aware alternative to .
:cdo s/old/new/ | update
:cdo {cmd} executes a command at every entry in the quickfix list, visiting each location in turn.
:packadd {name}
Vim 8+ and Neovim have a built-in package manager.
:'<,'>norm I//
After making a visual selection, :norm {commands} executes normal-mode keystrokes on every line in the range.
<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