What is the difference between \n and \r in Vim search patterns versus substitution replacements?
\n in search, \r in replacement
Vim uses \n and \r differently depending on whether they appear in a search pattern or a replacement string, and mixing them up is a common source of confusion.
category:
search
tags:
#search
#substitution
#newline
#patterns
#editing
How do I change the filetype of the current buffer to get correct syntax highlighting and indent rules?
:setfiletype {filetype} sets the filetype option for the current buffer only if it has not already been set.
category:
command-line
tags:
#config
#ex-commands
#formatting
How do I prevent accidental edits to a buffer by making it completely read-only?
:set nomodifiable locks a buffer so that no changes can be made at all — not even temporary ones.
category:
buffers-windows
tags:
#buffers
#editing
#normal-mode
#ex-commands
How do I make the gq operator format code with an external tool like prettier or black?
When formatprg is set, the gq operator pipes the selected text through that external program and replaces it with the program's output.
category:
editing
tags:
#editing
#formatting
#ex-commands
#config
How do I reset a Vim option back to its compiled default value?
Append & to any :set command to reset that option to its compiled-in default value — the value Vim shipped with before any vimrc or plugin changed it.
category:
config
tags:
#config
#options
#debugging
How do I see a summary of all previous quickfix lists from my current session and navigate between them?
Every time you run :grep, :vimgrep, :make, or :cexpr, Vim creates a new quickfix list and pushes the previous one onto a history stack.
category:
buffers-windows
tags:
#buffers-windows
#quickfix
#navigation
#ex-commands
How do I select or operate on the content of an HTML or XML tag using text objects?
Vim provides two built-in text objects for HTML and XML tags: it (inner tag) and at (a tag).
category:
editing
tags:
#text-objects
#editing
#visual-mode
#html
#normal-mode
How do I run a macro on every line in a specific line number range?
The :normal command lets you execute Normal mode keystrokes over a range of lines.
category:
macros
tags:
#macros
#normal
#range
#ex-commands
How do I configure Vim's command-line tab completion to show all matches and complete to the longest common prefix?
:set wildmode=list:longest
Vim's wildmode option controls how the command line behaves when you press to complete filenames, buffer names, or Ex commands.
category:
config
tags:
#config
#command-line
#completion
#ex-commands
How do I diff the current file against a specific git commit using vim-fugitive?
vim-fugitive's :Gdiffsplit opens a vertical split showing the current file diff against any git revision — not just HEAD.
category:
plugins
tags:
#plugins
#diff
#git
#buffers-windows
How do I reference just the extension, stem, or directory of the current file in a Vim command?
Vim exposes the current filename as % in Ex commands, and you can apply modifiers to extract specific parts of the path.
category:
command-line
tags:
#command-line
#ex-commands
#files
#editing
How do I append text to a named register programmatically without re-recording a macro?
Vim registers are just strings, and you can read and write them directly using the :let command.
category:
registers
tags:
#registers
#vimscript
#macros
#editing
How do I jump between merge conflict markers in a file?
During a git merge, Vim can navigate directly between conflict markers (>>>>>>) using ]n and [n.
category:
navigation
tags:
#navigation
#diff
#merge
#conflicts
How do I accept a flagged word as correct for the current session without permanently adding it to my spellfile?
zG marks the word under the cursor as correctly spelled in Vim's internal word list, which exists only for the current session.
category:
config
tags:
#config
#editing
#search
How do I make Vim automatically load a project-specific configuration file from the project directory?
Adding set exrc to your vimrc tells Vim to read a .
category:
config
tags:
#config
#ex-commands
#navigation
How do I turn off diff mode in all windows at once after comparing files?
The :diffoff! command exits diff mode in every window simultaneously.
category:
buffers-windows
tags:
#buffers-windows
#ex-commands
#editing
How do I get the current search match index and total count programmatically in Vim?
The searchcount() function returns a dictionary containing the current search state: which match the cursor is on, how many total matches exist, and whether the
category:
search
tags:
#search
#ex-commands
#registers
#completion
How do I reopen the last Telescope picker with my previous search and results still there?
The :Telescope resume command reopens the most recent Telescope picker, restoring the exact query string, filtered results, and cursor position from the last ti
category:
plugins
tags:
#telescope
#search
#navigation
#plugins
#fuzzy-find
How do I open a file found in Vim's path setting in a new split without typing the full path?
:sfind (split-find) searches Vim's path setting for a file matching the given name and opens it in a new horizontal split, all in one command.
category:
navigation
tags:
#navigation
#buffers
#windows
#ex-commands
How do I jump directly to the top-left or bottom-right window in a complex split layout?
When managing multiple splits, t jumps to the top-left window and b jumps to the bottom-right window.
category:
buffers-windows
tags:
#windows
#navigation
#buffers