How do I create custom text objects for my own operator-pending motions?
onoremap ih :<C-u>execute "normal! ?^==\+$\r:noh\rkvg_"<CR>
Vim lets you define custom text objects using operator-pending mode mappings (onoremap) and visual mode mappings (vnoremap).
category:
config
tags:
#config
#text-objects
#mappings
#vimrc
#advanced
How do I find out which file or plugin last set a particular Vim option?
:verbose set {option}? shows the current value of an option and reports exactly which file set it last — the full path and line number.
category:
command-line
tags:
#command-line
#config
#ex-commands
How do I selectively merge changes between two files in Vim's diff mode?
When comparing two files side by side with :diffsplit or vim -d, you often want to pull specific changes from one file into another rather than accepting all di
category:
buffers-windows
tags:
#buffers
#windows
#editing
#ex-commands
How do I open an existing buffer in a new tab page in Vim?
How it works The :tab sb N command opens buffer number N in a brand new tab page.
category:
buffers-windows
tags:
#buffers
#tabs
#ex-commands
#navigation
How do I customize Vim's statusline to show useful file information?
:set statusline=%f\ %y\ [%l/%L]
Vim's statusline option lets you build a custom status bar from format items.
category:
config
tags:
#config
#formatting
How do I quickly switch between the current file and the last edited file?
Pressing (Ctrl-6 on most keyboards) instantly toggles between the current buffer and the alternate file — the last file you were editing.
category:
buffers-windows
tags:
#navigation
#buffers
#normal-mode
#productivity
#windows
How do I set a mark that works across different files?
Uppercase marks (A-Z) are global marks — they remember not only the line and column position, but also the file where they were set.
category:
navigation
tags:
#navigation
#marks
#normal-mode
#buffers
#productivity
How do I insert the contents of another file into the current buffer?
The :r filename command reads the contents of filename and inserts them into the current buffer below the cursor line.
category:
command-line
tags:
#ex-commands
#editing
#buffers
How do I close all buffers except the current one in Vim?
How it works Vim does not have a built-in single command to close all buffers except the current one, but you can achieve this with a two-part command: :%bd e#.
category:
buffers-windows
tags:
#buffers
#ex-commands
#navigation
How do I force Vim to check if open files were changed externally and reload them?
The :checktime command tells Vim to check whether any open buffers have been modified outside of Vim and prompt you to reload them.
category:
buffers-windows
tags:
#buffers
#ex-commands
#editing
How do I view my complete Vim command and search history?
:history displays a numbered list of your recently entered Ex commands, giving you a full audit of what you have run in the current session (and across sessions
category:
command-line
tags:
#ex-commands
#command-line
#search
How do I move lines to a different position without using yank and paste?
The :move command (abbreviated :m) relocates lines to a new position in the buffer without touching any registers.
category:
editing
tags:
#ex-commands
#editing
How do I run the same command across all windows, buffers, or tabs?
:windo / :bufdo / :tabdo {command}
Vim's do commands iterate over collections and execute a command in each context.
category:
buffers-windows
tags:
#buffers
#windows
#tabs
#batch-editing
#ex-commands
How do I quickly switch between the current file and the last file I was editing?
:e # opens the alternate file — the file you were editing just before the current one.
category:
buffers-windows
tags:
#buffers
#editing
#ex-commands
#navigation
How do I list all lines matching a pattern across the current file and its includes?
The :ilist command searches for a pattern not only in the current buffer but also in files referenced by #include directives (or whatever 'include' is set to).
category:
search
tags:
#search
#ex-commands
#navigation
#editing
How do I build a custom statusline without plugins?
:set statusline=%f\ %m%r%h%w\ %=%l/%L\ %p%%
Vim's statusline option accepts printf-style format codes that display file info, position, mode, and any custom expression.
category:
config
tags:
#config
#statusline
#vimrc
#customization
How do I look up documentation for the keyword under the cursor?
Pressing K in normal mode runs a lookup program on the word under the cursor.
category:
navigation
tags:
#navigation
#help
#documentation
#normal-mode
#keywordprg
How do I view a side-by-side Git diff of staged changes inside Vim?
The vim-fugitive plugin provides :Gdiffsplit (and its vertical variant :Gvdiffsplit) to open a side-by-side diff view comparing the working tree version of a fi
category:
plugins
tags:
#plugins
#fugitive
#git
#diff
#staging
How do I capture the output of a Vim command into a register or buffer?
:redir @a | {cmd} | redir END
The :redir command redirects the output of Ex commands to a register, file, or variable instead of displaying it on the screen.
category:
command-line
tags:
#command-line
#ex-commands
#registers
#productivity
#advanced
How do I make Vim automatically jump to where I last edited when reopening a file?
autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
Vim remembers the last cursor position for every file you edit (stored in the viminfo or shada file), but by default it opens files at line 1.
category:
config
tags:
#config
#autocmd
#navigation
#vimrc
#productivity