How do I configure Vim to auto-save files when I switch away?
:set autowriteall and autocmd FocusLost * silent! wa
How it works Vim can be configured to automatically save your files when you switch to another window or application.
1019 results for "i" a""
:set autowriteall and autocmd FocusLost * silent! wa
How it works Vim can be configured to automatically save your files when you switch to another window or application.
:set nrformats+=alpha
By default, and only increment and decrement numbers (decimal, hex, and octal depending on format).
:%s/pattern//gn
The n flag on the substitute command reports the number of matches without performing any substitution.
"ayv
Using named registers with visual mode lets you store multiple independent snippets simultaneously.
:let @a = substitute(@a, 'old', 'new', 'g')
After recording a macro or yanking text into a named register, you may need to tweak it — fix a typo in a recorded macro, change a variable name in yanked tex
:g/^/m 0
This clever use of the :global command reverses every line in the current buffer.
command-line #editing #ex-commands #global #text-manipulation
qa ci"replacement<Esc> /next<CR> q
Macros can contain any Vim command including text objects, searches, and multi-key motions.
:Explore / :Vexplore / :Sexplore
Vim ships with netrw, a built-in file explorer that lets you browse directories, open files, create new files, rename, and delete — all without plugins.
buffers-windows #navigation #buffers #file-management #netrw #productivity
:'<,'>normal @q
The :'normal @q command runs macro q on every line of the visual selection.
:call setreg('a', @a, 'l')
Registers in Vim have a type — characterwise, linewise, or blockwise — that affects how their contents are pasted.
g&
The g& command repeats the last substitute command across the entire file.
!{motion}{program}
The ! operator in normal mode lets you pipe a range of text through any external program and replace it with the output.
{count}%
When used with a count, the % command jumps to the line at that percentage of the file.
:call setreg('a', @a . 'text', 'l')
How it works Vim provides two functions for advanced register manipulation: setreg() and getreg().
@a (within macro @b)
Vim macros can call other macros, enabling modular macro composition.
:g/pattern/m0
When working with large files, you sometimes need to reorganize content by pulling all lines matching a certain pattern to the top.
command-line #global #move #ex-commands #editing #command-line
:[{,]}s/old/new/g
By using the range [{,]}, you can limit a substitute command to the lines between the enclosing braces — effectively the current function or block.
:let @a = "value"
The :let @{reg} = expr command lets you assign any string or expression directly into a named register without entering insert mode or performing a yank.
`[ and `]
The ` [ ` and ] ` marks automatically track the boundaries of the last changed or yanked text.
<C-o>{command}
While typing in insert mode, you sometimes need to do a quick normal-mode action — center the screen, jump to a mark, or delete a word backward.