How do I embed Vim settings directly in a file so they apply automatically when it is opened?
# vim: set tabstop=2 shiftwidth=2 expandtab :
A modeline is a specially formatted comment that Vim reads when it opens a file and applies as local settings — no plugin or project-level vimrc required.
category:
config
tags:
#config
#modeline
#settings
#filetype
How do I see a summary of all previous quickfix lists from my current session and navigate between them?
Every time you run :grep, :vimgrep, :make, or :cexpr, Vim creates a new quickfix list and pushes the previous one onto a history stack.
category:
buffers-windows
tags:
#buffers-windows
#quickfix
#navigation
#ex-commands
How do I match only part of a search pattern for highlighting or substitution?
The \zs and \ze atoms let you define where the actual match starts and ends within a larger pattern.
category:
search
tags:
#search
#editing
#ex-commands
How do I change the case of captured text in a :substitute replacement?
\u / \l / \U / \L (in :s replacement)
Vim's :substitute replacement string supports case-conversion modifiers that let you uppercase or lowercase matched text without writing a separate command.
category:
search
tags:
#search
#editing
#ex-commands
#normal-mode
How do I run a command between two patterns but exclude the end marker line?
:/BEGIN/,/END/-1s/\s\+$//
When you need to clean or refactor block-like regions, Ex ranges can target lines between two search patterns without selecting text manually.
category:
command-line
tags:
#command-line
#ex-commands
#ranges
#search
#editing
How do I go back to a specific point in time using Vim's undo history?
Vim's :earlier and :later commands let you travel through your undo history using time-based offsets — not just individual changes.
category:
editing
tags:
#editing
#undo-redo
#time-travel
#history
How do I toggle all folding on and off globally with a single keystroke?
Pressing zi in normal mode toggles the foldenable option, which controls whether folds are active in the current window.
category:
config
tags:
#folding
#normal-mode
#config
How do I close a preview window from any other window without having to jump to it first?
Pressing z closes the preview window from any window in the current tab page.
category:
buffers-windows
tags:
#windows
#buffers
#navigation
#normal-mode
How do I count the number of matches for a search pattern?
The :%s/pattern//gn command counts how many times a pattern appears in the file without making any changes.
category:
search
tags:
#search
#ex-commands
#editing
How do I manually set the visual selection marks to define a precise Ex command range without entering visual mode?
Vim's ' marks record the start and end of the last visual selection and power the ' range used by Ex commands.
category:
navigation
tags:
#marks
#navigation
#visual-mode
#ex-commands
How do I load shell search output into a window-local location list?
:lgetexpr systemlist('rg --vimgrep TODO %') | lopen
When you want search results tied to only the current window, use :lgetexpr instead of :cgetexpr.
category:
buffers-windows
tags:
#location-list
#quickfix
#buffers
#command-line
#search
How do I rename, move, and delete files by editing the filesystem like a buffer with oil.nvim?
oil.
category:
plugins
tags:
#editing
#navigation
#plugins
#filesystem
How do I narrow an existing location list to only entries matching a regex without rerunning the search?
:packadd cfilter | Lfilter /pattern/
When you already have a populated location list, rerunning the original search just to focus on a subset is slow and disruptive.
category:
plugins
tags:
#plugins
#location-list
#quickfix
#search
#workflow
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 set Vim options from a Lua config in Neovim using vim.opt?
Neovim's vim.
category:
config
tags:
#config
#neovim
#lua
#options
#editing
How do I create a recursive macro that repeats itself until it fails?
A recursive macro calls itself at the end of its sequence, creating a loop that automatically repeats until a motion or command fails (such as hitting the last
category:
macros
tags:
#macros
#editing
#normal-mode
#registers
How do I make a macro that finds and operates on specific patterns?
qq /pattern<CR> {commands} q
By incorporating a search command inside a macro, you can make it jump to the next occurrence of a pattern before performing its edits.
category:
macros
tags:
#macros
#search
#recording
#workflow
#advanced
How do I run a substitution only within the exact characters of my visual selection?
:%s/\%Vpattern/replacement/g
The \%V atom restricts a regex match to the last visual selection — more precisely than :'s/.
category:
search
tags:
#search
#visual-mode
#ex-commands
#normal-mode
How do I count the number of lines containing a pattern without making any replacements?
The n flag in the substitute command suppresses the actual replacement and instead reports the match count.
category:
search
tags:
#search
#ex-commands
#substitute
#normal-mode
How do I filter a range of text through an external shell command in Vim?
The ! operator passes text selected by a motion through an external shell command, replacing it with the command's output.
category:
editing
tags:
#editing
#normal-mode
#ex-commands