How do I run vimgrep across a project using whatever pattern is currently in the search register?
:execute 'vimgrep /' . @/ . '/gj **/*'
If you already refined a search interactively with / or ?, retyping that pattern for project-wide grep is repetitive and error-prone.
category:
search
tags:
#search
#vimgrep
#quickfix
#registers
#workflow
How do I search files on 'path' and open the first match in the preview window instead of replacing my current buffer?
When you need quick context from another file but do not want to disturb your current editing window, :psearch gives you a clean workflow.
category:
buffers-windows
tags:
#buffers
#windows
#preview-window
#search
#navigation
How do I turn custom command output like file:line:col:message into a navigable quickfix list?
:setlocal errorformat=%f:%l:%c:%m | cexpr system('tool %') | copen
Not every linter or internal script speaks Vim quickfix format out of the box.
category:
command-line
tags:
#command-line
#quickfix
#errorformat
#linting
#workflow
How do I keep :mkview files focused on folds and cursor position without restoring unrelated local options?
:set viewoptions=folds,cursor,slash,unix
mkview and loadview are great for restoring editing context, but the default viewoptions can bring back more state than you actually want.
category:
config
tags:
#config
#views
#folding
#sessions
#workflow
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 buffer jumps prefer the last-used window that already shows the target buffer?
When jumps open the target buffer in an unexpected split, context switching gets expensive.
category:
buffers-windows
tags:
#buffers
#windows
#navigation
#config
How do I fully justify a selected text block to a fixed width using Vim's built-in justify plugin?
:packadd justify | :'<,'>Justify 72
Vim can wrap text, but full left-and-right justification is a different task.
category:
plugins
tags:
#plugins
#formatting
#visual-mode
#text-manipulation
How do I join wrapped paragraph lines while keeping blank-line paragraph separators?
When text is hard-wrapped (for example from email, logs, or copied docs), joining entire paragraphs manually is slow and error-prone.
category:
editing
tags:
#editing
#formatting
#ex-commands
#text-manipulation
How do I define a custom Ex command that forwards arguments with file completion?
:command! -nargs=* -complete=file W w <args>
When you repeatedly type a long Ex command with filenames, define a user command that keeps the behavior but shortens the keystrokes.
category:
command-line
tags:
#command-line
#ex-commands
#completion
#workflow
How do I make right-click extend a selection instead of opening a popup menu?
If you use the mouse occasionally in Vim, mousemodel=extend makes selection behavior much more predictable.
category:
config
tags:
#config
#visual-mode
#selection
#mouse
How do I populate a window-local location list from the current file and open it immediately?
:lgrep /pattern/ % | lopen
Quickfix is global, but sometimes you want a narrower search workspace tied to one window.
category:
search
tags:
#search
#location-list
#quickfix
#command-line
How do I run a substitution over every quickfix hit and save only changed files?
:cdo s/foo/bar/ge | update
When quickfix already contains exactly the lines you want to touch, :cdo is the safest way to batch-edit with tight scope.
category:
command-line
tags:
#command-line
#quickfix
#substitution
#refactoring
How do I append keystrokes to a macro without re-recording it?
Re-recording a long macro just to add one extra keystroke is wasteful and error-prone.
category:
macros
tags:
#macros
#registers
#automation
#editing
How do I search literally for the exact text I yanked last?
:let @/ = '\V' . escape(@0, '\')
When the text you yank contains regex characters, a normal / search can produce noisy or surprising matches.
category:
registers
tags:
#registers
#search
#regex
#command-line
How do I count substitution matches before changing anything?
:%s/pattern/replacement/gn
When you are about to run a broad substitution, it is often safer to measure impact first.
category:
command-line
tags:
#command-line
#ex-commands
#substitution
#search
How do I open the alternate buffer in a new split while keeping my current window unchanged?
If you often compare your current file against the previously visited buffer, replacing the current window is disruptive.
category:
buffers-windows
tags:
#buffers
#windows
#splits
#navigation
How do I swap the first two comma-separated fields on each line with one substitute command?
:%s/\v^([^,]+),([^,]+),/\2,\1,/<CR>
When CSV-like data has two columns in the wrong order, manually fixing each line is slow and error-prone.
category:
editing
tags:
#editing
#regex
#ex-commands
#formatting
How do I jump through several annotation keywords with one search command?
When you triage code, jumping among TODO, FIXME, and BUG markers quickly is often more useful than searching each token separately.
category:
search
tags:
#search
#regex
#navigation
#normal-mode
How do I refactor a recorded macro by rewriting its keystrokes with substitute()?
:let @q = substitute(@q, 'foo', 'bar', 'g')
Recorded macros are plain text stored in registers, which means you can refactor them instead of re-recording from scratch.
category:
macros
tags:
#macros
#registers
#automation
#ex-commands
How do I remove the most recent Ex command from command history in Vim?
When you run sensitive or noisy Ex commands, they stay in command history and can be recalled accidentally.
category:
command-line
tags:
#command-line
#history
#ex-commands
#privacy