How do I automatically fill a new file with a boilerplate template when creating it in Vim?
autocmd BufNewFile *.py 0r ~/.vim/templates/python.py
When you create a new file in Vim (e.
2125 results for "i{ a{"
autocmd BufNewFile *.py 0r ~/.vim/templates/python.py
When you create a new file in Vim (e.
d<C-v>2j
Vim lets you override the natural type of any motion by pressing v, V, or between the operator and the motion.
editing #editing #motions #visual-mode #advanced #normal-mode
:argdo %s/old/new/g | update
The :argdo command runs an Ex command on every file in the argument list (the files you opened Vim with, or added via :argadd).
\@!
In Vim's regex engine, \@! is the negative lookahead assertion.
\zs and \ze in a pattern
Vim's \zs ("match start") and \ze ("match end") atoms let you narrow the actual match region within a broader pattern context.
:set wildmenu wildmode=longest:full,full
By default, Vim's command-line tab completion just cycles through options.
: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
<C-x><C-k>
Vim's insert-mode completion system includes dictionary lookup via .
ZQ
ZQ is the discard-and-quit counterpart to ZZ.
/\(\<\w\+\>\)\_s\+\1\>
When writing or editing text, repeated words like "the the" or "is is" are a common typo that spell checkers often miss.
:cfdo %s/\<GetUser\>/FetchUser/ge | update
When quickfix has many matches per file, :cdo can execute your command repeatedly in the same buffer.
command-line #command-line #quickfix #refactoring #ex-commands #search
.\{-}
How it works In most regex engines, ? or +? make quantifiers non-greedy (matching as little as possible).
:%s/\zsparseData\ze(/processData/g
Vim's \zs and \ze atoms let you include context in your search pattern without including that context in the replacement.
:normal! {cmds}
:normal {cmds} executes normal-mode keystrokes from the command line, but it honors your custom key mappings — so remapped keys produce unexpected results in
command-line #ex-commands #macros #normal-mode #command-line
oil.nvim: edit directory listing like a buffer
oil.
:undojoin<CR>
By default, separate edits often become separate undo entries, which makes replaying or backing out a multi-part change noisy.
:%s/\w\+/(&)/g
In a Vim substitution, & in the replacement string expands to the entire matched text.
<C-w>}
How it works The } command opens a preview window showing the tag definition of the word under your cursor.
: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
g?
Vim has a built-in ROT13 encoding operator accessible via g?.
visual-mode #visual-mode #encoding #rot13 #text-transformation