How do I join every line matching a pattern with the line that follows it?
The :g/pattern/join command combines the :global command with :join to merge every line matching a pattern with the line immediately following it.
category:
command-line
tags:
#ex-commands
#editing
#command-line
#search
#normal-mode
How do I search for a character by its ASCII or Unicode code point value in a Vim pattern?
Vim's regex engine supports special atoms that match characters by their numeric value rather than their glyph.
category:
search
tags:
#search
#editing
#normal-mode
How do I save a file only if it has unsaved changes, without touching the file timestamp if nothing changed?
The :update command (abbreviated :up) writes the buffer to disk only if it has been modified since the last save.
category:
command-line
tags:
#ex-commands
#buffers
#editing
What is the difference between :norm and :norm! when running normal commands from the command line?
Both :norm and :norm! execute a sequence of Normal mode keystrokes from the command line or a script, but they differ in how they handle user-defined mappings.
category:
command-line
tags:
#ex-commands
#normal-mode
#macros
#vimscript
How do I run a substitution only on lines that match a specific pattern using the global command?
:g/pattern1/s/pattern2/replacement/g
Combining :g with :s lets you apply a substitution using two independent patterns: :g selects which lines to act on, and :s controls what gets replaced within t
category:
command-line
tags:
#ex-commands
#search
#editing
#normal-mode
How do I edit the contents of a macro register using Vimscript without re-recording it?
:call setreg("a", substitute(getreg("a"), "old", "new", "g"))
The getreg() and setreg() functions let you read and write register contents as plain strings, making it possible to surgically edit a macro without re-recordin
category:
registers
tags:
#registers
#macros
#vimscript
#ex-commands
How do I right-justify a line of text to a specific width using a built-in Vim command?
Vim has three built-in Ex commands for text alignment that most users never discover: :right [width] right-justifies lines, :left [width] left-justifies (strips
category:
editing
tags:
#editing
#formatting
#ex-commands
How do I prevent Vim's file completion and wildcard expansion from matching build artifacts or binary files?
:set wildignore defines a comma-separated list of glob patterns that Vim excludes from wildcard expansion and file completion.
category:
config
tags:
#config
#ex-commands
#navigation
How do I programmatically inject keystrokes into Vim's input queue from a function or mapping?
The feedkeys({keys}, {flags}) function inserts a string of keystrokes into Vim's input queue as if the user had typed them.
category:
command-line
tags:
#ex-commands
#macros
#config
#normal-mode
How do I move a tab to a different position in the tab bar?
:tabmove {n} repositions the current tab page to index n in the tab bar (0-indexed from the left).
category:
buffers-windows
tags:
#tabs
#buffers-windows
#navigation
How do I make a macro prompt for user input at a specific point during its execution?
<C-r>=input('Enter: ')<CR>
By embedding =input('prompt: ') inside a recorded macro, you can pause the macro at any point to ask for user input and insert the result.
category:
macros
tags:
#macros
#insert-mode
#registers
#editing
How do I add blank lines above or below the current line using vim-unimpaired?
vim-unimpaired (by Tim Pope) provides paired bracket mappings for dozens of common operations.
category:
plugins
tags:
#editing
#normal-mode
How do I transform or filter a list inline using Vimscript lambdas with map() and filter()?
map() and filter() with lambdas
Vim 8 introduced lambda expressions with the syntax {args -> expr}, enabling concise inline list transformations.
category:
config
tags:
#ex-commands
#normal-mode
How do I programmatically populate the quickfix list from Vimscript?
setqflist() lets you build the quickfix list from a Vimscript list of dictionaries rather than relying on compiler output or :vimgrep.
category:
command-line
tags:
#ex-commands
#buffers
How do I save and restore the cursor position and scroll state in a Vimscript function?
winsaveview() and winrestview()
When writing Vimscript functions or complex mappings that move the cursor, it is essential to restore the original view afterward so the user does not notice an
category:
config
tags:
#ex-commands
#normal-mode
How do I resolve a 3-way merge conflict by pulling changes from a specific buffer in diff mode?
When Vim's diff mode has three or more buffers open, :diffget (or do) without an argument is ambiguous — Vim cannot determine which buffer to pull from.
category:
buffers-windows
tags:
#buffers
#windows
#ex-commands
How do I prepend a value to the front of a comma-separated Vim option like path or runtimepath?
Vim's :set command supports three operators for modifying list-style options: += appends, -= removes, and ^= prepends.
category:
config
tags:
#config
#ex-commands
#navigation
How do I replace each match with an incrementing number using a counter variable in Vim?
:let i=0 | g/pattern/s/pattern/\=printf('%d', i+=1)/
By combining :let, the :g global command, and an expression substitution with \=, you can replace every match of a pattern with a unique incrementing number.
category:
search
tags:
#search
#ex-commands
#registers
#editing
How do I undo all changes made within the last hour using time-based undo?
Vim's undo history is annotated with timestamps, allowing you to travel back to any point in time using :earlier and forward using :later.
category:
command-line
tags:
#undo-redo
#ex-commands
#normal-mode
How do I see exactly which highlight groups are responsible for the color of the character under the cursor in Neovim?
When customizing a colorscheme or debugging unexpected syntax colors, it's difficult to know which highlight group to override.
category:
config
tags:
#config
#normal-mode