How do I save and restore the current window layout after temporarily changing window sizes in a Vim script?
The winrestcmd() function returns a string of Ex commands that, when executed, restore all window sizes to their state at the time of the call.
category:
config
tags:
#config
#vimscript
#windows
How do I autocomplete macro-defined identifiers from header files while in insert mode?
in insert mode triggers defined identifier completion — it searches for identifiers that match the partial word before the cursor by scanning #define statemen
category:
editing
tags:
#editing
#insert-mode
#completion
How do I run a command across all open buffers at once?
:bufdo %s/old/new/ge | update
The :bufdo command executes an Ex command in every loaded buffer.
category:
buffers-windows
tags:
#buffers
#ex-commands
#editing
#substitution
How do I run a Vim command without adding entries to the jump list?
:keepjumps is a command modifier that suppresses any jump list updates caused by the command that follows it.
category:
editing
tags:
#ex-commands
#navigation
#macros
#editing
How do I scroll the view horizontally so the cursor sits at the leftmost or rightmost visible column?
When nowrap is set and lines extend beyond the screen width, zs and ze snap the horizontal scroll position so the cursor sits exactly at the left or right edge
category:
navigation
tags:
#navigation
#scrolling
How do I view all the files Vim would search when resolving include-based completions and lookups?
:checkpath! recursively walks through every file reachable via Vim's include path and displays the full include tree.
category:
navigation
tags:
#navigation
#include
#completion
#ex-commands
How do I use case conversion metacharacters in Vim substitution replacement strings?
\U, \L, \u, \l, \e in :substitute replacement
Vim's substitute command supports in-replacement case conversion metacharacters that transform the case of matched text without extra scripting.
category:
search
tags:
#search
#ex-commands
#normal-mode
How do I edit a macro without re-recording it?
:let @q = substitute(@q, 'old', 'new', '')
Vim macros are stored as plain text in named registers, which means you can inspect and modify them directly using :let and :echo.
category:
macros
tags:
#macros
#registers
#editing
#normal-mode
How do I restrict a substitution to the range between two named marks?
Named marks can serve as range endpoints for any Ex command, including :substitute.
category:
search
tags:
#search
#marks
#substitution
#ex-commands
#editing
How do I jump back in the jumplist and automatically reveal and center the destination?
Jumping backward with is fast, but in folded or dense files it can land you in a collapsed section or near the edge of the screen, forcing extra cleanup keystro
category:
navigation
tags:
#navigation
#jumplist
#folding
#normal-mode
How do I search a project but keep results window-local using the location list instead of quickfix?
:lvimgrep /TODO/j **/* | lopen\<CR>
When you are working in multiple windows, quickfix can become noisy because it is shared globally across the editor session.
category:
search
tags:
#search
#ex-commands
#buffers
#windows
How do I use relative line offsets in Ex commands to target lines near the cursor?
Vim's Ex command addresses support arithmetic offsets relative to the current line (.
category:
command-line
tags:
#ex-commands
#editing
#navigation
#command-line
How do I configure Vim's :grep command to use a faster external search tool like ripgrep or ag?
:set grepprg={cmd} grepformat={fmt}
Vim's :grep command delegates to an external tool defined by grepprg, then parses the output according to grepformat to populate the quickfix list.
category:
search
tags:
#search
#ex-commands
#config
#buffers
How do I find which Vim scripts or functions are slow and causing performance issues?
:profile start profile.log
When Vim feels sluggish, the built-in :profile command lets you measure exactly how much time each script and function consumes.
category:
config
tags:
#config
#ex-commands
#performance
How do I run a macro a specific number of times without using a recursive macro?
Prefix a macro invocation with a count to execute it up to N times in a single command.
category:
macros
tags:
#macros
#registers
#normal-mode
#editing
How do I prevent autocommands from being registered multiple times when re-sourcing my vimrc?
augroup MyGroup | autocmd! | augroup END
Every time you run :source $MYVIMRC or :source % to reload your config, any bare autocmd calls are appended to Vim's autocommand table — no checking for dupli
category:
config
tags:
#config
#ex-commands
#autocmd
How do I automatically save and restore fold states between Vim sessions using autocmds?
autocmd BufWinLeave * mkview
By default, Vim forgets your folds, cursor position, and scroll state every time you close a file.
category:
config
tags:
#folding
#autocmd
#config
#persistence
#view
How do I copy the contents of one register into another register?
Vim's :let command lets you read and write register contents as strings, making it possible to copy, combine, or modify register values without ever leaving the
category:
registers
tags:
#registers
#ex-commands
#editing
#normal-mode
How do I create a custom operator that works with any motion in Vim?
:set operatorfunc=MyFunc<CR>g@{motion}
Vim's operatorfunc and g@ let you define custom operators that accept any motion or text object, just like built-in operators d, c, and y.
category:
config
tags:
#config
#mapping
#normal-mode
#editing
How do I execute a macro on each quickfix match and write files only when changed?
When you already have a precise quickfix list, :cdo is one of the safest ways to run a macro only where it matters.
category:
macros
tags:
#macros
#quickfix
#command-line
#automation