How do I use a Vimscript expression to compute the replacement text in a substitution?
Prefixing the replacement field of :s with \= makes Vim evaluate the rest as a Vimscript expression and use the result as the replacement string.
category:
command-line
tags:
#search
#ex-commands
#editing
#command-line
How do I match text only when it is followed by a specific pattern using zero-width lookahead?
Vim's regex engine supports zero-width positive lookahead via the \@= operator.
category:
search
tags:
#search
#regex
#lookahead
#advanced
#pattern
How do I remove duplicate consecutive lines using a substitute command?
This substitute command detects pairs of identical adjacent lines and collapses them into one, using a back-reference to match the repeated content.
category:
search
tags:
#search
#substitute
#regex
#editing
#duplicate-lines
How do I find out which file or plugin last set a particular Vim option?
:verbose set {option}? shows the current value of an option and reports exactly which file set it last — the full path and line number.
category:
command-line
tags:
#command-line
#config
#ex-commands
How do I prevent accidental edits to a buffer by making it completely read-only?
:set nomodifiable locks a buffer so that no changes can be made at all — not even temporary ones.
category:
buffers-windows
tags:
#buffers
#editing
#normal-mode
#ex-commands
How do I make the fold column appear only when needed and cap its width?
If you use folds heavily, a fixed fold column is a tradeoff: foldcolumn=0 hides useful fold cues, while a constant width wastes horizontal space in files that b
category:
config
tags:
#config
#folding
#ui
#windows
How do I overwrite existing text character by character without deleting first?
Replace mode lets you type over existing text one character at a time, like the "Insert" key behavior in traditional editors.
category:
editing
tags:
#editing
#normal-mode
#insert-mode
#replace
How do I search case-insensitively in Vim without changing global settings?
How it works By default, Vim searches are case-sensitive: /Hello will not match hello or HELLO.
category:
search
tags:
#search
#normal-mode
#ex-commands
How do I reindent a block of code using a visual selection?
After making a visual selection, pressing = applies Vim's auto-indent to every selected line at once.
category:
visual-mode
tags:
#visual-mode
#indentation
#editing
#formatting
How do I toggle the case of a rectangular column region across multiple lines?
Visual block mode () selects a rectangular column region, and pressing ~ at the end toggles the case of every character in that exact column range across all se
category:
visual-mode
tags:
#visual-mode
#editing
#case
#normal-mode
How do I open a specific buffer in a new split without navigating away from my current buffer?
:sbuffer {N} opens buffer number N in a new horizontal split, leaving your current window untouched.
category:
buffers-windows
tags:
#buffers-windows
#buffers
#windows
#navigation
How do I join all soft-wrapped lines in each paragraph into a single line?
The :g/^.
category:
command-line
tags:
#command-line
#editing
#global
#formatting
#paragraphs
How do I paste or reuse my last search pattern?
Vim stores your last search pattern in the / register.
category:
registers
tags:
#registers
#search
#insert-mode
#command-line
How do I sort a range of lines by piping them through an external sort command using the ! operator?
The ! operator in Vim filters a motion's text through an external shell command, replacing it with the output.
category:
editing
tags:
#editing
#motions
#ex-commands
How do I run normal mode edits on every line matching a pattern?
The :global command combined with :normal lets you execute arbitrary normal mode keystrokes on every line that matches a pattern.
category:
command-line
tags:
#global
#normal-mode
#editing
#ex-commands
#batch-editing
How do I re-indent a block of code to match the surrounding indentation?
The = operator performs smart indentation based on Vim's filetype-aware indent rules.
category:
editing
tags:
#editing
#indentation
#text-objects
#formatting
How do I run a normal mode command on every line in a visual selection?
After making a visual selection, :norm {commands} executes normal-mode keystrokes on every line in the range.
category:
visual-mode
tags:
#visual-mode
#editing
#ex-commands
#normal-mode
How do I run a substitute or filter command without Vim automatically repositioning my marks?
When Vim executes commands that move or reorder lines — such as :sort, :%!sort, or :s/// across ranges — it automatically adjusts named marks to follow the
category:
command-line
tags:
#ex-commands
#marks
#editing
#normal-mode
How do I make Vim's built-in file explorer display files as a tree rather than a flat list?
Vim ships with a built-in file browser called netrw, opened with :Explore (or :Ex).
category:
config
tags:
#config
#navigation
#netrw
#buffers
How do I copy a character from the line above or below while in insert mode?
When typing in insert mode, you can pull individual characters from adjacent lines without leaving insert mode.
category:
editing
tags:
#insert-mode
#editing
#completion