How do I create my own custom ex commands in Vim?
:command
:command lets you define new Ex (colon-prefixed) commands with custom names, optional argument handling, and completion.
command-line #command-line #ex-commands #config #normal-mode
:command
:command lets you define new Ex (colon-prefixed) commands with custom names, optional argument handling, and completion.
command-line #command-line #ex-commands #config #normal-mode
:set autochdir
The autochdir option tells Vim to automatically change the current working directory to the directory of the file in the active window whenever you switch buffe
:cnoremap %% <C-r>=expand('%:h').'/'<CR>
By mapping %% in command-line mode, you can type %% wherever you would normally type a path and have Vim automatically expand it to the directory of the current
:set switchbuf=useopen
The switchbuf option controls how Vim decides where to display a buffer when switching to it via commands like :sb, :cc, :cn, quickfix jumps, or .
buffers-windows #buffers-windows #navigation #ex-commands #config
:set keywordprg=:help
By default, pressing K in Normal mode runs the word under the cursor through an external program — usually man.
:set sessionoptions
The sessionoptions option (abbreviated ssop) is a comma-separated list of flags that determine what :mksession stores in the session file.
buffers-windows #buffers-windows #config #workflow #sessions
:setlocal {option}={value}
:setlocal sets an option only for the current buffer or window, leaving all other buffers and windows unaffected.
:set diffopt+=algorithm:patience,indent-heuristic
By default, Vim uses a basic longest-common-subsequence diff algorithm that can produce noisy, hard-to-read diffs.
zg and zw
When Vim's spell checker marks a word as incorrect but it is intentionally spelled that way (a name, abbreviation, or domain-specific term), you can permanently
# vim: set tabstop=2 shiftwidth=2 expandtab :
A modeline is a specially formatted comment that Vim reads when it opens a file and applies as local settings — no plugin or project-level vimrc required.
:execute
:execute evaluates a string as an Ex command, letting you build commands dynamically or embed special key sequences (like or ) as literal characters.
:augroup
Wrapping autocmds in a named augroup with autocmd! at the start prevents duplicate autocommands from accumulating every time your vimrc is sourced.
:packadd
Since Vim 8 and Neovim, Vim has a built-in package system that can load plugins directly from the filesystem — no external plugin manager required.
:iabbrev
:iabbrev defines insert mode abbreviations — short strings that expand automatically when you type a non-keyword character (like space or Enter) after them.
set path+=**
By adding to Vim's path option, you enable recursive directory search — which makes :find with tab completion a lightweight project-wide fuzzy finder, no plug
:set nrformats-=octal
Vim's and increment and decrement numbers under the cursor.
set wildcharm=<Tab>
By default, pressing in a : mapping inserts a literal tab character rather than triggering wildmenu completion.
let @q = 'keystrokes'
Macros recorded with q{register} are stored in registers and lost when Vim exits.
:match {group} /{pattern}/
:match lets you apply a highlight group to any pattern in the current window without touching the buffer or its syntax rules.
:set nrformats+=alpha
By default, and only increment and decrement numbers (decimal, hex, and octal depending on format).