How do I schedule a command to run after a delay in Vim?
:call timer_start(1000, {-> execute('echo "done"')})
Vim's timerstart() function lets you schedule code to run after a specified delay in milliseconds.
:call timer_start(1000, {-> execute('echo "done"')})
Vim's timerstart() function lets you schedule code to run after a specified delay in milliseconds.
:doautocmd User MyEvent
Vim's User event type lets you define custom events that fire on demand.
:cnoremap <C-a> <Home>
Vim's command line has limited navigation by default.
:command -complete=file -nargs=1 E edit <args>
When defining custom commands with :command, the -complete option adds tab completion for arguments.
command-line #command-line #completion #custom-command #tab-complete
:execute 'normal! ' . count . 'j'
The :execute command evaluates a string as an Ex command, enabling dynamic command construction.
:setlocal nobuflisted
Setting nobuflisted removes a buffer from the :ls output and buffer-switching commands like :bnext/:bprev, while keeping it loaded and accessible.
buffers-windows #buffers-windows #buffers #unlisted #management
:%s/\v(old)/\=toupper(submatch(0)[0]).tolower(submatch(0)[1:])/g
Standard substitutions don't preserve the original case of matched text.
:tabonly | %bdelete | edit #
When your Vim session becomes cluttered with many tabs and buffers, you can clean up by closing all tabs except the current one with :tabonly, then deleting all
:cabbrev tn tabnew
Command-line abbreviations with cabbrev let you create short aliases for frequently used Ex commands.
command-line #command-line #abbreviation #shortcuts #productivity
:set autoread | autocmd FocusGained * checktime
When working with Git, build tools, or collaborators, files may change outside Vim.
buffers-windows #buffers-windows #autoread #file-detection #external-changes
:nnoremap ]b :bnext<CR>
Mapping ]b and [b to :bnext and :bprev creates an intuitive bracket-style navigation for buffers, matching the convention used by unimpaired.
buffers-windows #buffers-windows #navigation #mapping #buffers
:setlocal nomodifiable
While :set readonly prevents accidental writes, nomodifiable goes further by preventing any changes to the buffer contents entirely.
buffers-windows #buffers-windows #readonly #modifiable #protection
<C-w>_ and <C-w>|
When working with multiple splits, you sometimes need to focus on one window temporarily without closing the others.
:set suffixesadd+=.js,.ts,.py
In many programming languages, import statements reference modules without file extensions (e.
:set virtualedit=block
By default, Vim's visual block mode () is limited by line length — if some lines are shorter than others, the block selection gets ragged.
<C-f> (from command-line mode)
When you are partway through typing a long or complex Ex command on the : prompt, you can press to open the command-line window.
:keeppattern %s/old/new/g
When you run a :s or :%s substitute command, Vim updates the search register (@/) with the substitution pattern.
command-line #ex-commands #search #editing #registers #substitute
:%norm! A;
The :norm! (or :normal!) command executes normal mode keystrokes while ignoring all user-defined mappings.
:checktime
The :checktime command tells Vim to check whether any open buffers have been modified outside of Vim and prompt you to reload them.
:bufdo %s/old/new/ge | update
The :bufdo command executes an Ex command in every loaded buffer.
buffers-windows #buffers #ex-commands #editing #substitution