How do I run a substitution without overwriting my current search pattern?
The :keeppatterns modifier runs an Ex command — typically :s, :g, or :v — without modifying @/ (the last search pattern) or the command history.
category:
command-line
tags:
#ex-commands
#search
#substitution
#command-line
#scripting
How do I save all modified buffers at once without switching to each one?
When working across multiple files, you often have unsaved changes in several buffers.
category:
command-line
tags:
#buffers
#ex-commands
#editing
How do I create a macro by typing it out instead of recording it interactively?
Recording macros with q works well for simple sequences, but complex macros with special keys can be hard to get right in one take.
category:
macros
tags:
#macros
#registers
#ex-commands
How do I delete all blocks of text between two patterns throughout a file?
The :g (global) command can operate on ranges, not just single lines.
category:
search
tags:
#search
#editing
#ex-commands
How do I sort lines by a specific column or field in Vim?
Vim does not have a built-in multi-column sort, but you can leverage the external sort command to sort selected lines by any field.
category:
editing
tags:
#editing
#sorting
#ex-commands
#external-commands
#command-line
How do I search for a pattern across all files in a project using Vim's built-in grep?
While external tools like grep or ripgrep are fast, Vim's built-in :vimgrep has a key advantage: it populates the quickfix list directly, so you can jump betwee
category:
search
tags:
#search
#quickfix
#ex-commands
#navigation
How do I find out which scripts or plugins are slowing down my Vim startup?
When Vim feels sluggish to start, the built-in :profile command lets you measure exactly how much time each script, function, or plugin takes to load.
category:
config
tags:
#config
#performance
#debugging
#ex-commands
How do I run the same command across all open buffers at once?
When you need to apply the same change to every file you have open in Vim, switching to each buffer manually is tedious and error-prone.
category:
buffers-windows
tags:
#buffers
#ex-commands
#editing
#batch
How do I control exactly where a new split window appears in Vim?
By default, Vim places horizontal splits below and vertical splits to the right (controlled by splitbelow and splitright).
category:
buffers-windows
tags:
#buffers
#windows
#ex-commands
#splits
How do I run a command without moving the cursor or changing the scroll position?
:let view=winsaveview() | {cmd} | call winrestview(view)
When writing Vimscript functions or mappings, commands like :substitute, gg, or :%normal will move the cursor and change the scroll position.
category:
command-line
tags:
#ex-commands
#editing
#vimscript
#navigation
How do I set breakpoints and debug Vimscript functions interactively?
:breakadd func {funcname}
Vim has a built-in debugger for Vimscript that most users never discover.
category:
config
tags:
#ex-commands
#config
#debugging
#vimscript
How do I set a different statusline for a specific buffer or window?
:setlocal statusline=%f\ %m\ %y\ [%l/%L]
The :setlocal statusline command lets you override the global statusline for a specific window.
category:
config
tags:
#config
#statusline
#ex-commands
#buffers
How do I run a Vim command in a restricted sandbox to prevent side effects?
The :sandbox command modifier executes any Ex command in a restricted environment where potentially dangerous operations are blocked.
category:
command-line
tags:
#command-line
#security
#ex-commands
#sandbox
How do I ignore whitespace changes when using Vim's diff mode?
When comparing files in Vim's diff mode, whitespace-only changes (extra spaces, changed indentation) can clutter the diff and hide meaningful edits.
category:
config
tags:
#config
#diff
#editing
#ex-commands
How do I swap two parts of a line using capture groups in a Vim substitution?
:s/\v(pattern1)(pattern2)/\2\1/
Vim's substitute command supports capture groups (also called backreferences), which let you rearrange matched portions of text.
category:
search
tags:
#search
#substitute
#regex
#editing
#ex-commands
How do I move all lines matching a pattern to the top of the file?
When working with large files, you sometimes need to reorganize content by pulling all lines matching a certain pattern to the top.
category:
command-line
tags:
#global
#move
#ex-commands
#editing
#command-line
How do I set up Vim to parse errors from my compiler or linter into the quickfix list?
Vim ships with built-in compiler plugins that configure makeprg and errorformat for popular tools.
category:
command-line
tags:
#ex-commands
#config
#editing
How do I move lines to a different position without using yank and paste?
The :move command (abbreviated :m) relocates lines to a new position in the buffer without touching any registers.
category:
editing
tags:
#ex-commands
#editing
How do I sort lines based on a specific column or pattern match rather than the whole line?
Vim's :sort command accepts a pattern that controls which part of each line is used as the sort key.
category:
command-line
tags:
#ex-commands
#editing
#formatting
How do I create a key mapping that behaves differently depending on context?
:nnoremap <expr> j (v:count == 0 ? 'gj' : 'j')
Expression mappings use the flag to evaluate a Vimscript expression at the time the key is pressed.
category:
config
tags:
#config
#normal-mode
#ex-commands
#navigation