How do I insert a newline in the replacement string of a :s substitution?
:s/,/,\r/g
In Vim's :substitute command, \r in the replacement string inserts a literal newline — it splits the line at that point.
2277 results for "@a"
:s/,/,\r/g
In Vim's :substitute command, \r in the replacement string inserts a literal newline — it splits the line at that point.
qa:s/\t/ /g\njq
Record a macro that substitutes all tabs with spaces on the current line, then moves down.
@=
The @= command lets you type a Vimscript expression and execute the result as if it were a macro.
getchar()
getchar() blocks and waits for the user to press a key, returning its numeric character code.
"ayip
Use "ayip to yank the inner paragraph into register a.
:%!sort
Use :%!command to filter the entire buffer through a shell command.
:%s/; /;\r/g
In the replacement part, use \r to insert a newline.
qaciwi(<C-r>")<Esc>wq
Record a macro that changes the inner word, types an opening paren, pastes the original word, types a closing paren, and moves to the next word.
:let @a = '...'
When a recorded macro contains a typo or needs a small tweak, you can modify it directly via the :let command rather than re-recording the entire sequence.
gg"aVGy
Go to the first line with gg, then visually select from there to the last line with VG, and yank into register a.
qa0f=40i <Esc>040lDjq
Record a macro that inserts spaces before = to pad to column 40, then trims excess.
"aP
Use "aP (uppercase P) to paste the contents of register a before the cursor position, as opposed to "ap which pastes after.
"ap
In visual mode, "ap replaces the selected text with the contents of register a.
:tabdo %s/old/new/g
Use :tabdo to execute a command in every tab page.
:sview {file}
The :sview command opens a file in a horizontal split window with the buffer set to read-only.
buffers-windows #buffers-windows #windows #navigation #ex-commands
@a (within macro @b)
Vim macros can call other macros, enabling modular macro composition.
getreg()
The getreg({name}) function returns the content of any register as a string.
:[range]right [width]
Vim's :right command right-aligns text by padding lines with leading spaces up to a given width.
qa/^$/\ndd@aq
Record a macro that searches for blank lines, deletes them, and recurses.
mA / 'A
Uppercase marks (A-Z) are global marks — they remember not only the line and column position, but also the file where they were set.
navigation #navigation #marks #normal-mode #buffers #productivity