How do I save my current window and return to it after navigating other windows from a script or function?
:let winid = win_getid() | ... | call win_gotoid(winid)
The wingetid() and wingotoid() functions let you bookmark a window by its stable integer ID and jump back to it reliably.
category:
buffers-windows
tags:
#buffers-windows
#ex-commands
#macros
How do I edit the contents of a macro using Vimscript string functions without re-recording it?
:let @q = substitute(@q, 'from', 'to', 'g')
Macros are stored as plain text in named registers, so you can manipulate them with any Vimscript string function.
category:
macros
tags:
#macros
#registers
#ex-commands
How do I rearrange or transform captured groups in a substitution using Vimscript?
:s/\(\w\+\) \(\w\+\)/\=submatch(2) . ' ' . submatch(1)/
The submatch(N) function lets you access individual capture groups inside a \= (expression replacement) in a substitution.
category:
search
tags:
#search
#editing
#ex-commands
#registers
How do I move to the end of the visible screen line when text is soft-wrapped?
The g$ command moves the cursor to the last character of the current screen line, not the end of the logical line.
category:
navigation
tags:
#navigation
#motions
#wrap
#normal-mode
How do I use a pattern-based range with an offset to operate on lines relative to a search match?
:/pattern/+N and :/pattern/-N
Vim's Ex command ranges can use search patterns as line addresses, and those addresses can include a numeric offset (+N or -N) to target lines relative to the m
category:
command-line
tags:
#ex-commands
#search
#command-line
#editing
How do I make Vim reuse an already-open window or tab when jumping to a quickfix entry?
:set switchbuf=useopen,usetab
By default, Vim opens a new window (or reloads the buffer in the current window) whenever you navigate to a quickfix entry, tag, or :buffer command — even if
category:
buffers-windows
tags:
#buffers-windows
#quickfix
#options
#config
How do I change an option's global default without affecting the current buffer's local value?
Vim maintains two values for most options: a global default that applies to new windows and buffers, and a local copy that can be overridden per-buffer or per-w
category:
config
tags:
#config
#ex-commands
#options
How do I filter the quickfix list to only show entries matching a pattern?
Vim ships with an optional built-in package called cfilter that adds :Cfilter and :Lfilter commands for narrowing down quickfix and location list entries by pat
category:
command-line
tags:
#ex-commands
#quickfix
#search
#command-line
How do I scroll the screen while also jumping to the first non-blank character of the current line?
Vim has two sets of scroll-and-position commands: zt/zz/zb (which reposition the screen but keep the cursor column intact) and z/z.
category:
navigation
tags:
#navigation
#scrolling
#normal-mode
How do I suppress Vim's startup splash screen and reduce noisy status messages?
The shortmess option is a string of single-character flags that tell Vim which messages to suppress or abbreviate.
category:
config
tags:
#config
#messages
#startup
#options
How do I jump directly to a specific point in the undo history by change number?
:undo {N} lets you jump directly to the undo tree state after change number N was applied.
category:
editing
tags:
#undo-redo
#editing
#advanced
How do I insert a new line of text after every line matching a pattern using the global command?
Combining :global with :put = lets you insert synthesized lines of content after every line matching a pattern — without plugins or complex macros.
category:
command-line
tags:
#command-line
#ex-commands
#editing
#global
How do I type special characters and symbols using Vim's built-in digraph system in insert mode?
Vim's digraph system lets you insert special characters, accented letters, and symbols by typing a memorable two-character sequence.
category:
editing
tags:
#insert-mode
#special-characters
#unicode
#editing
How do I add a visual indicator at the start of soft-wrapped continuation lines?
When wrap is enabled, Vim wraps long lines at the screen edge, but there is no built-in visual marker to distinguish a wrapped continuation from a brand-new lin
category:
config
tags:
#config
#editing
#formatting
How do I export the current buffer as syntax-highlighted HTML from within Vim?
Vim ships with a built-in plugin that converts the current buffer into a standalone HTML file, complete with your exact syntax highlighting colors.
category:
command-line
tags:
#command-line
#editing
#ex-commands
How do I display the full absolute path of the current file without leaving normal mode?
Pressing prints the current filename, buffer status, and cursor position in the status line.
category:
navigation
tags:
#navigation
#buffers-windows
#normal-mode
Why doesn't \n insert a newline in a :s replacement, and what should I use instead?
In Vim substitutions, \n and \r behave differently depending on whether they appear in the search pattern or the replacement string — a common gotcha that sur
category:
search
tags:
#search
#editing
#ex-commands
#normal-mode
How do I cycle through the numbered delete registers using the dot command?
When you paste from a numbered register with "1p, Vim's dot command (.
category:
registers
tags:
#registers
#editing
#normal-mode
#undo-redo
How do I pass special keys like Ctrl or arrow keys to :execute normal! in a Vimscript function or mapping?
:execute "normal! \<{key}>"
When building dynamic :execute normal! calls in Vimscript, you must use double-quoted strings with the \ notation so Vim interprets the special key codes.
category:
macros
tags:
#macros
#ex-commands
#normal-mode
How do I manually add the current position to the jump list before making a large movement?
Vim's jump list automatically records your position whenever you make large motions (like G, /pattern, or ).
category:
navigation
tags:
#navigation
#marks
#normal-mode