How do I execute a macro from bottom to top over a selected range?
Running a macro over a range usually goes top to bottom, but that can break when the macro inserts or deletes lines.
category:
macros
tags:
#macros
#ex-commands
#visual-mode
#normal-mode
#refactoring
How do I reverse the order of all lines in a file?
The :g/^/m0 command is a clever use of Vim's global command to reverse every line in the file.
category:
command-line
tags:
#editing
#ex-commands
#global-command
#lines
What are Vim's built-in character class shortcuts for search patterns?
How it works Vim provides shorthand character classes that save you from writing out full bracket expressions.
category:
search
tags:
#search
#normal-mode
#ex-commands
How do I highlight multiple different patterns simultaneously using Vim's built-in match commands?
Vim provides three independent match slots — :match, :2match, and :3match — each of which highlights a pattern using a specified highlight group.
category:
search
tags:
#search
#highlighting
#config
#normal-mode
How do I run a shell command from Vimscript and capture its output as a list of individual lines?
systemlist({cmd}) runs a shell command and returns the output as a list of strings, one per line — unlike system() which returns everything as a single string
category:
command-line
tags:
#vimscript
#ex-commands
#registers
#macros
How do I remove accidental Enter keystrokes from a recorded macro?
:let @q = substitute(@q, '\n', '', 'g')
A common macro failure mode is accidentally hitting while recording.
category:
macros
tags:
#macros
#registers
#debugging
#vimscript
How do I zero-pad issue numbers without changing the # prefix?
:%s/#\zs\d\+/\=printf('%04d', submatch(0))/g
For log files, changelogs, or issue references, you sometimes need fixed-width numeric IDs without touching surrounding syntax.
category:
editing
tags:
#editing
#ex-commands
#substitute
#regex
#text-processing
How do I remove trailing spaces only within the currently selected visual block?
Sometimes you need to clean alignment artifacts in a rectangular region without touching the rest of each line.
category:
visual-mode
tags:
#visual-mode
#substitution
#regex
#formatting
#editing
How do I open Vim help pages in a new tab instead of a split?
By default, :help opens in a horizontal split, which can feel cramped.
category:
buffers-windows
tags:
#buffers
#windows
#tabs
How do I run a quickfix-wide replace without changing jumps or search history?
:cdo keepjumps keeppatterns %s/\<OldSymbol\>/NewSymbol/ge | update
When you run :cdo over a large quickfix list, Vim can leave your jump list noisy and your last search pattern overwritten.
category:
command-line
tags:
#quickfix
#ex-commands
#search
#editing
#refactoring
How do I suppress Vim's startup splash screen and reduce noisy status messages?
The shortmess option is a string of single-character flags that tell Vim which messages to suppress or abbreviate.
category:
config
tags:
#config
#messages
#startup
#options
How do I replace only part of a match in :substitute without capture groups?
When your match has a stable prefix but you only want to replace the trailing segment, \zs is often cleaner than introducing extra capture groups.
category:
search
tags:
#search
#ex-commands
#formatting
#editing
How do I swap two adjacent words on a line using a substitute command in Vim?
:s/\v(\w+)\s+(\w+)/\2 \1/
By using capture groups in a substitute command with very magic mode (\v), you can swap two adjacent words in a single operation.
category:
search
tags:
#search
#editing
#substitute
#regex
#text-objects
How do I capture command-line output directly into a register?
:redir @a | messages | redir END<CR>
When debugging a session or building repeatable edits, it is useful to turn command output into editable text.
category:
registers
tags:
#registers
#command-line
#debugging
#workflow
How do I fill quickfix from ripgrep output without leaving Vim?
:cexpr system('rg --vimgrep "TODO"')
When you already know you want an external search tool, :cexpr lets you import results directly into quickfix without opening a terminal buffer or shelling out
category:
command-line
tags:
#command-line
#quickfix
#search
#workflow
How do I recursively search files and load matches into quickfix in one command?
:vimgrep /\<TODO\>/gj **/*.lua | copen
When you want a project-wide TODO pass without leaving Vim, :vimgrep plus quickfix is a strong built-in workflow.
category:
search
tags:
#search
#quickfix
#command-line
#project-navigation
#ex-commands
How do I save only real file buffers when running bufdo across many open buffers?
:bufdo if &buftype ==# '' | update | endif
bufdo is powerful for multi-buffer automation, but a naive write pass can error on special buffers (help, terminal, quickfix, prompts).
category:
buffers-windows
tags:
#buffers
#windows
#ex-commands
#automation
#workflow
How do I delete all lines between two delimiter patterns without removing the delimiters themselves?
:g/BEGIN/+1,/END/-1 delete
By combining the :global command with a relative address range, you can delete the content between repeating delimiter pairs while leaving the delimiters intact
category:
command-line
tags:
#command-line
#ex-commands
#search
#editing
How do I jump to the Nth next search match instead of pressing n repeatedly?
Like most Vim motions, the n and N search repeat commands accept a count prefix.
category:
search
tags:
#search
#navigation
#motions
How can I print only arglist files that still contain trailing whitespace before bulk cleanup?
:argdo if search('\s\+$', 'nw') | echo expand('%') | endif
Before running destructive cleanup across many files, it helps to know which files will actually change.
category:
command-line
tags:
#command-line
#search
#whitespace
#arglist
#refactoring