How do I split a single-line code statement into multiple lines or join them back in Vim?
gS / gJ
The splitjoin.
plugins #plugins #splitjoin #editing #refactoring #formatting
2277 results for "@a"
gS / gJ
The splitjoin.
plugins #plugins #splitjoin #editing #refactoring #formatting
ftdetect/{filetype}.vim
Vim automatically sources every file in ftdetect/ directories on the runtimepath when filetype detection runs.
<C-g>u
By default, Vim treats an entire Insert mode session (from entering Insert mode to pressing ) as a single undo unit.
:lcd {dir}
:lcd (local cd) sets the working directory for the current window only, leaving other windows at their previous directory.
buffers-windows #buffers-windows #navigation #ex-commands #config
:keeppatterns {cmd}
Whenever Vim runs a command that involves searching — :g, :s, :v, or even moving the cursor with / — it overwrites the last search register (@/).
\@<= and \@<!
Vim's \@<= and \@<! atoms let you write zero-width lookbehind assertions — they check what comes before the match position without consuming characters.
gN
Most users know gn for selecting the next search match, but its counterpart gN is the real power move when you need to work backward through matches.
visual-mode #visual-mode #search #motions #editing #normal-mode
:verbose nmap <lhs>
When key behavior is inconsistent, the root cause is usually mapping precedence.
command-line #command-line #mappings #debugging #config #normal-mode
yiww"_ciw\<C-r>0\<Esc>
When you are doing repetitive refactors, cw is fast but it overwrites the unnamed register with the replaced text.
qQ
Recording a macro with an uppercase register letter appends to the existing macro in the corresponding lowercase register instead of overwriting it.
:%s/\(pattern1\)\(pattern2\)/\2\1/g
Vim's substitute command supports capture groups that let you match parts of text, remember them, and rearrange or reuse them in the replacement.
:s/pattern/\U&/g
Vim's :substitute command supports case-transformation escape sequences in the replacement string.
search #search #substitute #ex-commands #editing #text-objects
:sort r /pattern/
The :sort r /pattern/ command sorts lines using the matched portion of the regex as the sort key.
\@= and \@<=
Vim's regex engine supports zero-width lookahead and lookbehind assertions — \@= and \@<= — which let you match text based on surrounding context without in
"qp {edit} 0"qy$ dd
When you record a macro and realize it has a mistake, the easiest fix is to paste the macro's keystrokes as text, edit them, and yank the corrected version back
:let view=winsaveview() | {cmd} | call winrestview(view)
When writing Vimscript functions or mappings, commands like :substitute, gg, or :%normal will move the cursor and change the scroll position.
:let @/='\V'.escape(@", '\\')
When you yank text that contains regex characters like .
:!command
The :!command syntax lets you execute any shell command directly from within Vim without leaving the editor.
:set gdefault
By default, :s/old/new/ only replaces the first occurrence of a pattern on each line.
autocmd BufWritePre * :%s/\s\+$//e
By adding an autocmd for the BufWritePre event, you can make Vim automatically strip trailing whitespace from every line each time you save.