How do I remove trailing whitespace from all lines?
:%s/\s\+$//
The :%s/\s\+$// command removes trailing whitespace (spaces and tabs) from every line in the file.
:%s/\s\+$//
The :%s/\s\+$// command removes trailing whitespace (spaces and tabs) from every line in the file.
:m {line-number}
The :m (move) command moves the current line to after the specified line number.
:t {line-number}
The :t (copy/transfer) command duplicates the current line and places it after the specified line number.
:%normal command
The :normal command executes normal mode commands programmatically on a range of lines.
:vimgrep /pattern/ **/*.ext
The :vimgrep command searches for a pattern across multiple files and populates the quickfix list with the results.
:grep pattern files
The :grep command runs an external grep tool and loads the results into Vim's quickfix list.
:%s/\(group\)/\1/g
Capture groups in Vim substitute let you match parts of a pattern and reuse them in the replacement.
:'<,'>s/old/new/g
After making a visual selection, you can run a substitute command that only affects the selected text.
:%s/pattern/\r/g
In the replacement part of :s, \r inserts a newline.
:%s/\(\w\+\)/\u\1/g
Vim provides case-conversion atoms in substitute replacements: \u uppercases the next character, \l lowercases it, \U uppercases until \e, and \L lowercases unt
:[{,]}s/old/new/g
By using the range [{,]}, you can limit a substitute command to the lines between the enclosing braces — effectively the current function or block.
:%s/\V literal.text/replacement/g
The \V (very nomagic) flag treats all characters as literal except for \.
:cdo s/old/new/g
The :cdo command executes a command on every entry in the quickfix list.
:tags
The :tags command displays the tag stack, showing all the tag jumps you have made with and their return points.
:tselect
When a tag has multiple definitions (e.
<C-t>
The command pops the tag stack and returns to the position from which you last used or :tag.
:lnext and :lprev
The location list is a per-window alternative to the quickfix list.
:cnext and :cprev
The quickfix list holds a set of file positions, typically from compiler errors, grep results, or other tools.
<C-]>
The command jumps to the definition of the keyword under the cursor using tag files.
:<line-number>
When you know the exact line number you want to navigate to, the colon command is the quickest way to get there.