How do I move all lines matching a pattern to the top of the file?
When working with large files, you sometimes need to reorganize content by pulling all lines matching a certain pattern to the top.
category:
command-line
tags:
#global
#move
#ex-commands
#editing
#command-line
How do I set up Vim to parse errors from my compiler or linter into the quickfix list?
Vim ships with built-in compiler plugins that configure makeprg and errorformat for popular tools.
category:
command-line
tags:
#ex-commands
#config
#editing
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 sort lines based on a specific column or pattern match rather than the whole line?
Vim's :sort command accepts a pattern that controls which part of each line is used as the sort key.
category:
command-line
tags:
#ex-commands
#editing
#formatting
How do I filter text through an external program using a motion in normal mode?
The ! operator in normal mode lets you pipe a range of text through any external program and replace it with the output.
category:
editing
tags:
#editing
#normal-mode
#ex-commands
#formatting
How do I run a command on lines near each match, not just the matching line itself?
The :g (global) command normally operates on lines that match a pattern.
category:
command-line
tags:
#ex-commands
#editing
#search
#global
How do I expand or shrink a visual selection based on the syntax tree using Treesitter?
Neovim's nvim-treesitter plugin provides incremental selection based on the abstract syntax tree (AST) of your code.
category:
plugins
tags:
#visual-mode
#plugins
#editing
#navigation
How do I populate the quickfix list from the output of an external shell command?
:cexpr system('grep -rn TODO .')
The :cexpr command evaluates an expression and parses the result as quickfix entries using the current errorformat.
category:
command-line
tags:
#ex-commands
#search
#editing
#buffers
How do I add line numbers to the beginning of every line using a substitute expression?
Vim's substitute command supports expressions in the replacement string using \=.
category:
search
tags:
#search
#ex-commands
#editing
#formatting
How do I change the case of a specific column of text using visual block mode?
Visual block mode lets you select rectangular regions of text, which means you can target a specific column and apply case changes only to that area.
category:
visual-mode
tags:
#visual-mode
#editing
#text-objects
#formatting
How do I fix the indentation of a code block without affecting surrounding code?
When editing code with messy indentation — after a paste, a merge conflict, or a refactor — you often need to fix just one block rather than the entire file
category:
editing
tags:
#editing
#indentation
#text-objects
#formatting
How do I modify the contents of a register without re-recording it?
: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
category:
registers
tags:
#registers
#macros
#ex-commands
#editing
How do I turn a visual selection of lines into a numbered list?
:s/^/\=line('.') - line("'<") + 1 . '. '/
When you need to quickly number a set of lines — such as TODO items, steps, or bullet points — you can use a visual selection combined with a substitution e
category:
visual-mode
tags:
#visual-mode
#editing
#ex-commands
#formatting
#substitute
How do I move all lines matching a pattern to the top or bottom of a file?
The :global command combined with :move lets you restructure a file by relocating all lines that match a pattern.
category:
editing
tags:
#ex-commands
#editing
#text-objects
How do I diff two files that are already open in Vim splits?
You often have two files open side by side and want to compare them without leaving Vim or launching vimdiff.
category:
navigation
tags:
#buffers
#windows
#editing
#navigation
How do I run a substitute command without changing my current search pattern?
When you run a :s or :g command, Vim updates the search register (@/) with the pattern you used.
category:
command-line
tags:
#ex-commands
#search
#editing
#command-line
How do I insert a literal control character or special key in insert mode?
When you need to insert a literal tab character despite expandtab being set, or embed a control character like ^M (carriage return) into your text, in insert mo
category:
editing
tags:
#editing
#insert-mode
#special-characters
#control-characters
How do I insert the same text multiple times without a macro or copy-paste?
Vim's insert commands accept a count prefix that repeats everything you type.
category:
editing
tags:
#editing
#insert-mode
#normal-mode
#formatting
How do I find accidentally repeated words like 'the the' in a document?
When writing or editing text, repeated words like "the the" or "is is" are a common typo that spell checkers often miss.
category:
search
tags:
#search
#editing
#ex-commands
#formatting
How do I move the cursor to the other end of a visual selection to adjust it?
When you start a visual selection, the cursor is at one end and the anchor is at the other.
category:
visual-mode
tags:
#visual-mode
#navigation
#editing
#motions