How do I perform the same operation across multiple files using the argument list?
:args **/*.js | argdo %s/old/new/ge | update
The argument list (arglist) is Vim's mechanism for loading a set of files and running commands across all of them.
category:
command-line
tags:
#command-line
#ex-commands
#arglist
#productivity
#batch
#editing
How do I auto-indent a block of code using visual mode?
Pressing = in visual mode auto-indents the selected lines according to Vim's built-in indentation rules.
category:
visual-mode
tags:
#editing
#visual-mode
#indentation
#formatting
#productivity
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 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 change the content between HTML tags without manually selecting it?
The cit command deletes everything between the nearest pair of HTML/XML tags and drops you into insert mode, ready to type the replacement.
category:
editing
tags:
#editing
#text-objects
#normal-mode
#html
#tags
How do I quickly replace the text inside quotes without manually selecting it?
The ci" command deletes everything inside the nearest pair of double quotes and drops you into insert mode, ready to type the replacement.
category:
editing
tags:
#editing
#text-objects
#normal-mode
#productivity
How do I quickly change an entire sentence in Vim?
The cis command deletes the entire sentence under the cursor and drops you into insert mode, ready to type a replacement.
category:
editing
tags:
#editing
#text-objects
#normal-mode
#motions
#prose
How do I change text from the cursor up to a specific character?
The ct{char} command deletes everything from the cursor up to (but not including) the specified character and drops you into insert mode.
category:
editing
tags:
#editing
#motions
#normal-mode
#text-objects
#productivity
What is the difference between cw and ciw when changing a word?
The cw and ciw commands both change a word, but they behave differently depending on cursor position.
category:
editing
tags:
#editing
#text-objects
#motions
#normal-mode
#productivity
How do I collect all lines matching a pattern and copy them to the end of the file or a register?
The :g command combined with yank A (uppercase A to append) lets you collect every line matching a pattern into a single register without overwriting previous c
category:
command-line
tags:
#editing
#ex-commands
#global-command
#registers
#filtering
How do I append text to the end of multiple lines at once using visual block mode?
Visual block mode combined with $A lets you append text to the end of multiple lines simultaneously, even when those lines have different lengths.
category:
visual-mode
tags:
#editing
#visual-mode
#block-mode
#productivity
#insert-mode
How do I specify line ranges in Ex commands to target specific parts of a file?
Every Ex command in Vim can be preceded by a range that specifies which lines it should operate on.
category:
command-line
tags:
#command-line
#ex-commands
#ranges
#editing
#productivity
How do I set up auto-correct abbreviations in Vim to fix common typos?
Vim's abbreviation system automatically expands short text sequences as you type, making it perfect for auto-correcting typos, inserting boilerplate snippets, o
category:
config
tags:
#editing
#insert-mode
#config
#productivity
#auto-correct
How do I split the window vertically in Vim?
The :vsplit command (or :vs for short) splits the current window vertically, creating a new window side-by-side with the current one.
category:
buffers-windows
tags:
#buffers-windows
#windows
#ex-commands
How do I swap two characters in Vim?
The xp command swaps the character under the cursor with the character to its right.
category:
editing
tags:
#editing
#normal-mode
How do I switch between split windows in Vim?
The (Ctrl+w Ctrl+w) command cycles the cursor to the next window in the current tab.
category:
buffers-windows
tags:
#buffers
#windows
#navigation
#normal-mode
How do I toggle the case of a character in Vim?
The ~ command toggles the case of the character under the cursor — uppercase becomes lowercase and vice versa — then advances the cursor one position to the
category:
editing
tags:
#editing
#normal-mode
#formatting
How do I paste text from outside Vim without messing up indentation?
The :set paste command enables paste mode, which temporarily disables auto-indentation, smart tabs, and other insert-mode features that can mangle text pasted f
category:
config
tags:
#config
#editing
#insert-mode
How do I undo the last change in Vim?
The u command undoes the last change you made in normal mode.
category:
editing
tags:
#editing
#undo-redo
#normal-mode
How do I uppercase a word in Vim?
The gUiw command converts the entire word under the cursor to uppercase.
category:
editing
tags:
#editing
#text-objects
#normal-mode
#formatting