How do I close all tabs and buffers except the current one?
: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
Search Vim Tricks
Searching...: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
<C-r>=system("date")<CR>
The expression register (=) is one of Vim's most powerful yet underused features.
/\(function\s\+\)\zs\w\+
Vim's \zs and \ze atoms let you control which part of a matched pattern gets highlighted and operated on.
<C-w>_ and <C-w>=
When working with multiple splits, you often want to focus on one window by making it as large as possible, then restore equal sizing when you're done.
g; and g,
Vim tracks every position where you made a change in the changelist.
qqq qq{commands}@qq @q
A recursive macro calls itself at the end of its recording, causing it to repeat automatically until a motion fails (like j at the last line).
:let @+ = expand('%:p')
Sometimes you need to share or use the full path of the file you're editing — for a terminal command, a config file, or a chat message.
) and (
The ) and ( motions move by sentence boundaries.