How do I switch from the active command line into the command-line window to edit the command with full Vim power?
Pressing while you are already typing in the Vim command line (:), search line (/ or ?), or input prompt switches you into the command-line window with the curr
category:
command-line
tags:
#command-line
#ex-commands
#editing
#normal-mode
How do I open the command-line window mid-command to edit it with full Vim capabilities?
<C-f> (in command-line mode)
When you're already on the Vim command line and realize you need complex edits — inserting text from multiple positions, reordering arguments, or referencing
category:
command-line
tags:
#command-line
#ex-commands
#editing
How do I clear the contents of a register?
The :let @{register} = "" command empties a register.
category:
registers
tags:
#registers
#ex-commands
How do I search for text only within a visual selection?
The \%V atom restricts a search pattern to only match inside the most recent visual selection.
category:
search
tags:
#search
#visual-mode
#regex
#substitution
#advanced
How do I append text to a register instead of replacing it?
The "Ayy command appends the current line to register a instead of overwriting it.
category:
registers
tags:
#registers
#yank
#editing
#normal-mode
How do I paste the contents of a register at a specific line number without moving my cursor?
How it works The :put Ex command pastes the contents of a register after a specified line.
category:
editing
tags:
#editing
#registers
#ex-commands
How do I run a macro on every line in a visual selection?
The :'normal @a command executes the macro stored in register a on every line within the current visual selection.
category:
macros
tags:
#macros
#visual-mode
#ex-commands
#editing
How do I search for a whole word only, excluding partial matches?
The \ atoms create word boundaries in a search pattern, matching only complete words and not substrings within larger words.
category:
search
tags:
#search
#normal-mode
How do I prevent duplicate autocommands when reloading vimrc?
augroup name | autocmd! | ... | augroup END
Using augroup with autocmd! inside prevents duplicate autocommands from accumulating when you reload your vimrc.
category:
config
tags:
#config
#command-line
#ex-commands
How do I use capture groups to rearrange text in a Vim substitute command?
:%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.
category:
search
tags:
#search
#substitution
#regex
#ex-commands
#editing
How do I search and replace with case-preserving substitution?
:%S/old/new/g (vim-abolish)
vim-abolish by Tim Pope provides :%S (Subvert), a substitute command that preserves the case pattern of the original text.
category:
plugins
tags:
#plugins
#search
#editing
How do I highlight all search matches in the file?
The hlsearch option highlights all matches of the current search pattern throughout the file, making it easy to see where matches occur.
category:
search
tags:
#search
#config
How do I search and replace text containing special characters?
:%s/\V literal.text/replacement/g
The \V (very nomagic) flag treats all characters as literal except for \.
category:
search
tags:
#search
#ex-commands
How do I access the text from my last insert session?
The .
category:
registers
tags:
#registers
#editing
#normal-mode
How do I run a command on every open buffer?
The :bufdo command executes an Ex command on every buffer in the buffer list.
category:
buffers-windows
tags:
#buffers
#ex-commands
How do I see the search match count in the statusline?
The shortmess option controls which messages are shortened.
category:
search
tags:
#search
#config
How do I automatically remove trailing whitespace every time I save a file?
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.
category:
config
tags:
#config
#autocmd
#editing
#whitespace
#vimrc
How do I apply commands to specific line ranges?
Ex commands accept range specifiers that control which lines are affected.
category:
command-line
tags:
#command-line
#ex-commands
How do I jump to the start of the next method or function?
The ]m command jumps to the start of the next method in Java-style code.
category:
navigation
tags:
#navigation
#motions
#normal-mode
How do I create a macro that converts lines to a numbered list?
This simple macro inserts a list number prefix at the beginning of each line.
category:
macros
tags:
#macros
#editing