How do I create abbreviations for the Vim command line to fix typos like W and Q?
:cnoreabbrev {lhs} {rhs}
:cnoreabbrev defines a non-recursive command-line abbreviation — like noremap but for Ex commands.
:cnoreabbrev {lhs} {rhs}
:cnoreabbrev defines a non-recursive command-line abbreviation — like noremap but for Ex commands.
{args -> expr}
Vim 8.
:e ++enc={encoding}
When Vim auto-detects the wrong character encoding — mojibake where é shows as é is a classic symptom — you can reload the current buffer with a specifi
:iabbrev <expr> {trigger} {expression}
The flag on :iabbrev turns the right-hand side into a Vimscript expression that is evaluated at expansion time rather than stored as a literal string.
%:t:r
Vim's % special character expands to the current filename and accepts a chain of colon-delimited modifiers.
command-line #command-line #ex-commands #editing #navigation
:silent !{cmd}
Running :!cmd in Vim shows the command's output and then pauses with a "Press ENTER or type command to continue" prompt.
:let maplocalleader = ','
Vim provides two separate leader keys: (global) and (local to the current buffer).
:mkview / :loadview
:mkview saves a snapshot of the current window — its fold states, cursor position, and local option values — to a view file on disk.
buffers-windows #folding #buffers-windows #config #ex-commands
:%retab!
The :retab command converts leading whitespace according to the current tabstop and expandtab settings, but it only touches indentation at the start of lines.
nnoremap <key> :<C-u>call MyFunc(v:count)<CR>
When writing custom mappings that call Vimscript functions, a common pitfall is that any count you type before the key (e.
:'a,'bs/old/new/g
Named marks can serve as range endpoints for any Ex command, including :substitute.
:%d
The % range address in Ex commands stands for the entire file — it is shorthand for 1,$ (first line to last line).
:compiler
Vim ships with built-in compiler plugins for many languages and tools — including gcc, python, cargo, eslint, tsc, and more.
command-line #ex-commands #config #buffers-windows #command-line
:next
When Vim is opened with multiple files (e.
command-line #buffers-windows #ex-commands #navigation #editing
:keepmarks
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
<C-u> (command line)
When you are typing a long Ex command on the : prompt and realise you've made a mistake, pressing erases everything from the cursor back to the beginning of the
command-line #command-line #ex-commands #editing #insert-mode
:cfirst and :clast
:cfirst and :clast jump directly to the first or last entry in the quickfix list, skipping all intermediate results.
%:r
The %:r expression expands to the current filename with its extension removed (the "root" of the filename).
setreg()
The setreg(reg, value, type) and getreg(reg, 1, 1) functions give you full programmatic control over registers, including their type (characterwise, linewise, o
vim.api.nvim_buf_call()
vim.