How do I run a macro only on lines that match a specific pattern?
The :g (global) command combined with :normal @a lets you execute a recorded macro only on lines matching a pattern.
category:
macros
tags:
#macros
#ex-commands
#global-command
#editing
#automation
How do I jump several older change locations at once in Vim instead of repeating g;?
Most users know g; moves backward through the changelist, but fewer people use a count with it.
category:
navigation
tags:
#navigation
#changelist
#motions
#normal-mode
How do I edit a macro in-place using Vimscript without re-recording it?
:let @a = substitute(@a, "old", "new", "g")
When a recorded macro has a typo or wrong command buried inside it, you don't have to re-record the entire thing.
category:
macros
tags:
#macros
#registers
#vimscript
#editing
How do I run a substitution across multiple files using Vim's argument list?
:argdo {cmd} executes an Ex command against every file in the argument list—the set of files you opened Vim with or set explicitly with :args.
category:
command-line
tags:
#command-line
#ex-commands
#editing
#buffers
How do I run a search and replace across multiple files?
:cfdo %s/old/new/g | update
The :cfdo %s/old/new/g update command performs a search and replace across every file in the quickfix list and saves each one.
category:
command-line
tags:
#command-line
#ex-commands
#search
#editing
How do I edit the contents of a macro register using Vimscript without re-recording it?
:call setreg("a", substitute(getreg("a"), "old", "new", "g"))
The getreg() and setreg() functions let you read and write register contents as plain strings, making it possible to surgically edit a macro without re-recordin
category:
registers
tags:
#registers
#macros
#vimscript
#ex-commands
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 make Vim automatically jump to where I last edited when reopening a file?
autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
Vim remembers the last cursor position for every file you edit (stored in the viminfo or shada file), but by default it opens files at line 1.
category:
config
tags:
#config
#autocmd
#navigation
#vimrc
#productivity
How do I run commands without polluting the jump list?
When writing scripts or running commands that move the cursor (like :g, :s, or :normal), Vim normally adds each cursor position to the jump list.
category:
command-line
tags:
#navigation
#ex-commands
#normal-mode
#editing
How do I repeat the last substitute command quickly?
The & command in normal mode repeats the last :s substitution on the current line.
category:
search
tags:
#search
#substitution
#ex-commands
#repeat
#normal-mode
How do I create an incrementing number sequence across multiple lines?
Selecting a column of identical numbers with visual block mode and pressing g turns them into an incrementing sequence.
category:
visual-mode
tags:
#visual-mode
#editing
How do I run a Vim command without adding entries to the jump list?
:keepjumps is a command modifier that suppresses any jump list updates caused by the command that follows it.
category:
editing
tags:
#ex-commands
#navigation
#macros
#editing
How do I run a command on lines between two search patterns?
Vim allows pattern-based ranges in Ex commands, letting you operate on lines between two search matches.
category:
command-line
tags:
#command-line
#ranges
#patterns
#ex-commands
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 add line numbers to multiple lines using visual block?
Visual block insert can add numbered prefixes to lines.
category:
visual-mode
tags:
#visual-mode
#editing
How do I save and restore the current window layout after temporarily changing window sizes in a Vim script?
The winrestcmd() function returns a string of Ex commands that, when executed, restore all window sizes to their state at the time of the call.
category:
config
tags:
#config
#vimscript
#windows
How do I get real-time asynchronous linting and fixing in Vim?
The ALE (Asynchronous Lint Engine) plugin provides real-time linting and automatic fixing for dozens of languages without blocking your editor.
category:
plugins
tags:
#plugins
#ale
#linting
#async
#workflow
#formatting
How do I convert a visually selected block of text to uppercase or lowercase?
In visual mode, pressing U converts all selected characters to uppercase and u converts them to lowercase.
category:
visual-mode
tags:
#visual-mode
#editing
#normal-mode
How do I view my complete Vim command and search history?
:history displays a numbered list of your recently entered Ex commands, giving you a full audit of what you have run in the current session (and across sessions
category:
command-line
tags:
#ex-commands
#command-line
#search
How do I open a URL under the cursor in my web browser from Vim?
The gx command opens the URL, file path, or identifier under the cursor using the system's default handler.
category:
navigation
tags:
#navigation
#netrw
#workflow
#browser
#normal-mode