How do I see a diff of my unsaved changes compared to the version on disk?
The command :w !diff % - pipes the current buffer's contents to an external diff command that compares it against the saved file on disk.
category:
buffers-windows
tags:
#buffers-windows
#ex-commands
#editing
#navigation
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 embed Vim settings inside a file using modelines?
Modelines are special comments at the top or bottom of a file that Vim reads to apply file-specific settings.
category:
config
tags:
#config
#modeline
#per-file
#settings
How do I make part of a search pattern optional so it matches with or without that sequence?
Vim's \%[seq] atom makes the sequence seq optional in a pattern — matching any prefix of the sequence (including nothing).
category:
search
tags:
#search
#editing
#ex-commands
How do I collapse long runs of blank lines to a single empty line?
When files pass through formatters, generators, or repeated edits, they often accumulate noisy vertical gaps.
category:
editing
tags:
#editing
#substitute
#formatting
#cleanup
How do I enable Ctrl-A and Ctrl-X to increment and decrement binary numbers like 0b1010 in Vim?
Vim's and commands increment and decrement numbers under the cursor, but by default they only handle decimal and hexadecimal.
category:
config
tags:
#editing
#config
#increment
#normal-mode
#numbers
How do I run a command on every entry in the location list, like a window-local quickfix?
Vim maintains two parallel systems for collections of file positions: the quickfix list (global, one per Vim session) and the location list (local to each windo
category:
command-line
tags:
#command-line
#ex-commands
#buffers
#search
How do I use Neovim's built-in native snippet support to expand snippets without a plugin?
Neovim 0.
category:
plugins
tags:
#editing
#completion
#insert-mode
How do I set a mark and jump back to it later?
The ma command sets a mark named a at the current cursor position.
category:
navigation
tags:
#navigation
#marks
#normal-mode
How do I open the file whose name is under the cursor in a new tab?
gf reads the filename under the cursor and opens it in a new tab page, keeping your current buffer untouched.
category:
navigation
tags:
#navigation
#buffers-windows
#tabs
How do I replay the last executed macro with a single key in Neovim?
In Neovim, the Q key is mapped to replay the last executed macro — the same as @@ in both Vim and Neovim.
category:
macros
tags:
#macros
#neovim
#normal-mode
How do I show documentation for the selected completion item in a popup window?
Adding popup to completeopt makes Vim display extra information — such as function signatures or documentation — for the currently highlighted completion it
category:
config
tags:
#completion
#insert-mode
#config
#editing
How do I stop <C-a> from treating leading-zero numbers as octal?
:set nrformats-=octal<CR>
By default, Vim may treat numbers with leading zeros as octal when you use and for increment/decrement.
category:
config
tags:
#config
#editing
#numbers
#normal-mode
#increment
How do I zero-pad every number in a buffer using one substitute expression?
:%s/\d\+/\=printf('%04d', submatch(0))/g
When you need fixed-width numeric fields, manually editing each number is slow and error-prone.
category:
editing
tags:
#editing
#ex-commands
#formatting
#regex
How do I open a file by name by searching through my project directories?
:find searches for a file in all directories listed in the path option and opens it in the current window.
category:
navigation
tags:
#navigation
#ex-commands
#buffers
How do I capture the output of a Vim command into a register or buffer?
:redir @a | {cmd} | redir END
The :redir command redirects the output of Ex commands to a register, file, or variable instead of displaying it on the screen.
category:
command-line
tags:
#command-line
#ex-commands
#registers
#productivity
#advanced
How do I search for a pattern only when it's preceded or followed by another pattern?
/\(pattern\)\@<=target or /target\(pattern\)\@=
Vim supports zero-width assertions (lookahead and lookbehind) in its regex engine.
category:
search
tags:
#search
#regex
#lookahead
#lookbehind
#advanced
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 create a custom operator that works with motions and text objects?
:set operatorfunc=MyFunc<CR>g@
Vim lets you define custom operators that behave like built-in ones (d, c, y) — they wait for a motion or text object, then act on the selected region.
category:
config
tags:
#config
#normal-mode
#motions
#text-objects
#mapping
How do I trigger a code action at the cursor position using Neovim's built-in LSP?
Since Neovim 0.
category:
plugins
tags:
#lsp
#neovim
#code-action
#editing
#plugins