How do I set each window's local working directory to its buffer path?
:windo lcd %:p:h<CR>
When multiple splits point at files from different projects, relative-path commands can become inconsistent and error-prone.
Search Vim Tricks
Searching...:windo lcd %:p:h<CR>
When multiple splits point at files from different projects, relative-path commands can become inconsistent and error-prone.
[b and ]b
The vim-unimpaired plugin by Tim Pope adds symmetric [ and ] bracket mappings for navigating common Vim lists.
plugins #navigation #buffers #quickfix #plugins #normal-mode
:redir @a | messages | redir END<CR>
When debugging a session or building repeatable edits, it is useful to turn command output into editable text.
/foo\zsbar\zebaz<CR>
Sometimes you need Vim to match a long structural pattern but only treat one piece of it as the actual match.
{count}n
Like most Vim motions, the n and N search repeat commands accept a count prefix.
:g/BEGIN/+1,/END/-1 delete
By combining the :global command with a relative address range, you can delete the content between repeating delimiter pairs while leaving the delimiters intact
dv{motion}
In operator-pending mode — after typing an operator like d, y, or c but before the motion — you can press v, V, or to override the motion type to characterw
gm
The gm command moves the cursor horizontally to the middle of the current screen width on the current line.
:%s/\(\d\+\)/\=submatch(1)+1/g
Vim's substitute command supports using a VimScript expression as the replacement by prefixing it with \=.
y/{pattern}<CR>
Any operator in Vim can take a search motion as its argument.
:s#pattern#replacement#g
Vim's substitution command accepts any non-alphanumeric, non-whitespace character as the delimiter — not just /.
:set listchars=
The listchars option controls exactly which invisible characters Vim highlights when list mode is active.
:set makeprg=
The makeprg option defines the command that :make runs.
let {var} =<< {marker}
Vim 8.
:try / :catch / :endtry
Vimscript has a structured exception handling system using :try, :catch, :finally, and :endtry.
function! {name}#{funcname}() in autoload/{name}.vim
Vim's autoload mechanism lets you place functions in autoload/*.
: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.
`0
Vim automatically saves your cursor position when you exit, storing it as the 0 mark in the viminfo file (or shada file in Neovim).
:set winheight=999 winminheight=5
Setting winheight to a very large number forces Vim to always try to make the focused window as tall as possible.
: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.