How do I control what state gets saved when I use :mkview to snapshot a window?
:set viewoptions=cursor,folds,slash,unix
The viewoptions setting is a comma-separated list that determines exactly what :mkview (and the auto-save view pattern) stores in a view file.
category:
config
tags:
#config
#folding
#views
#options
#ex-commands
How do I run a find-and-replace across multiple files at once using the argument list?
:args **/*.py | argdo %s/old/new/ge | update
Combining :args, :argdo, and :update gives you a powerful in-editor multi-file search and replace without leaving Vim.
category:
command-line
tags:
#ex-commands
#editing
#macros
#search
How do I open a file by name by searching through my project directories?
:find searches for a file in all directories listed in the path option and opens it in the current window.
category:
navigation
tags:
#navigation
#ex-commands
#buffers
How do I run a substitution without displacing my marks?
:keepmarks %s/pattern/replacement/g
The :keepmarks modifier prevents Vim from adjusting mark positions when a buffer-modifying command runs.
category:
search
tags:
#marks
#search
#editing
#ex-commands
How do I convert space-indented code to tab-indented code in Vim?
:set noexpandtab | retab!
When you inherit space-indented code and need to switch to tabs, :retab! (with the bang) converts groups of spaces into tabs throughout the file.
category:
editing
tags:
#indentation
#editing
#ex-commands
#formatting
How do I automatically apply the preferred LSP code action without a selection prompt in Neovim?
vim.lsp.buf.code_action({ apply = true, filter = function(a) return a.isPreferred end })
When an LSP server marks a code action as isPreferred (e.
category:
plugins
tags:
#normal-mode
#ex-commands
How do I add a description to a Neovim keymapping so it appears in which-key and :map output?
vim.keymap.set('n', '{key}', {fn}, { desc = '{description}' })
When defining keymaps with vim.
category:
config
tags:
#normal-mode
#macros
#ex-commands
How do I sort a range of lines by piping them through an external sort command using the ! operator?
The ! operator in Vim filters a motion's text through an external shell command, replacing it with the output.
category:
editing
tags:
#editing
#motions
#ex-commands
How do I send a range of lines as stdin to a shell command without modifying the buffer?
The :[range]w !{cmd} command writes a range of lines to the standard input of a shell command, leaving the buffer completely unchanged.
category:
command-line
tags:
#ex-commands
#command-line
#shell
#normal-mode
How do I run a global command only on lines that match two different patterns simultaneously?
:g/pattern1/g/pattern2/command
Vim's :g command can be nested — the command part of one :g can itself be another :g.
category:
command-line
tags:
#ex-commands
#search
#editing
#command-line
How do I make part of a search pattern optional so it matches with or without that sequence?
Vim's \%[seq] atom makes the sequence seq optional in a pattern — matching any prefix of the sequence (including nothing).
category:
search
tags:
#search
#editing
#ex-commands
How do I open a file in Vim without triggering any autocmds for faster loading?
When you have heavy autocmds registered for BufRead, BufEnter, or FileType events — such as LSP clients, formatters, or syntax processors — opening a large
category:
command-line
tags:
#command-line
#ex-commands
#buffers-windows
#config
How do I use case conversion metacharacters in Vim substitution replacement strings?
\U, \L, \u, \l, \e in :substitute replacement
Vim's substitute command supports in-replacement case conversion metacharacters that transform the case of matched text without extra scripting.
category:
search
tags:
#search
#ex-commands
#normal-mode
How do I persistently highlight a pattern in Vim using a specific highlight group without a plugin?
:match, :2match, and :3match give you three independent highlight slots that overlay patterns on the buffer using any highlight group — without touching the s
category:
search
tags:
#search
#config
#normal-mode
#ex-commands
How do I control windows using Ex commands in scripts and mappings instead of Ctrl-W shortcuts?
:wincmd {key} is the Ex command equivalent of every {key} window shortcut.
category:
buffers-windows
tags:
#buffers-windows
#windows
#ex-commands
#normal-mode
How do I restrict a substitute command to only the text within my last visual selection using the percent-V atom?
The \%V atom in Vim's regex engine matches only within the area of the last visual selection.
category:
search
tags:
#search
#visual-mode
#substitute
#advanced
#ex-commands
How do I insert a blank line above or below the current line without entering insert mode?
Using :put ='' with an empty expression lets you insert blank lines in normal mode without ever entering insert mode.
category:
editing
tags:
#editing
#normal-mode
#ex-commands
#expression-register
#blank-line
How do I add custom filetype detection for a new file extension without modifying Vim's built-in filetypes?
Vim automatically sources every file in ftdetect/ directories on the runtimepath when filetype detection runs.
category:
plugins
tags:
#config
#ex-commands
How do I define a custom Ex command that can accept a line range or count like built-in Vim commands?
:command -range {Name} ...
Custom Ex commands defined with :command -range can be called with a line range (e.
category:
command-line
tags:
#command-line
#ex-commands
#config
How do I run a normal mode command on every visually selected line?
After making a visual selection, :'normal {command} runs any normal-mode command on each selected line individually.
category:
visual-mode
tags:
#visual-mode
#ex-commands
#normal-mode
#editing