How do I use capture groups to rearrange text in a Vim substitute command?
:%s/\(pattern1\)\(pattern2\)/\2\1/g
Vim's substitute command supports capture groups that let you match parts of text, remember them, and rearrange or reuse them in the replacement.
category:
search
tags:
#search
#substitution
#regex
#ex-commands
#editing
How do I collect all lines matching a pattern and copy them to the end of the file or a register?
The :g command combined with yank A (uppercase A to append) lets you collect every line matching a pattern into a single register without overwriting previous c
category:
command-line
tags:
#editing
#ex-commands
#global-command
#registers
#filtering
How do I specify line ranges in Ex commands to target specific parts of a file?
Every Ex command in Vim can be preceded by a range that specifies which lines it should operate on.
category:
command-line
tags:
#command-line
#ex-commands
#ranges
#editing
#productivity
How do I split the window vertically in Vim?
The :vsplit command (or :vs for short) splits the current window vertically, creating a new window side-by-side with the current one.
category:
buffers-windows
tags:
#buffers-windows
#windows
#ex-commands
How do I view the contents of all registers in Vim?
The :registers command displays the contents of all Vim registers, showing you exactly what text is stored in each one.
category:
registers
tags:
#registers
#ex-commands
#normal-mode
How do I save a file I opened without sudo permissions?
The :w !sudo tee % command lets you save a file that requires root permissions, even if you forgot to open Vim with sudo.
category:
command-line
tags:
#command-line
#ex-commands
#editing
How do I display a vertical line at a specific column width?
The :set colorcolumn=80 command displays a vertical highlight at column 80, giving you a visual guide for line length.
category:
config
tags:
#config
#formatting
#ex-commands
How do I set the tab width in Vim?
:set tabstop=4 shiftwidth=4 expandtab
The :set tabstop=4 shiftwidth=4 expandtab command configures Vim to use 4-space indentation with spaces instead of tab characters.
category:
config
tags:
#config
#indentation
#ex-commands
How do I show invisible characters like tabs and trailing spaces?
The :set list command makes invisible characters visible by displaying them as special symbols.
category:
config
tags:
#config
#ex-commands
#editing
How do I sort selected lines in Vim?
The :'sort command sorts the currently selected lines in visual mode alphabetically.
category:
visual-mode
tags:
#visual-mode
#ex-commands
#editing
#formatting
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 run a macro on every line in a visual selection?
The :'normal @a command executes the macro stored in register a on every line within the current visual selection.
category:
macros
tags:
#macros
#visual-mode
#ex-commands
#editing
How do I run a shell command from inside Vim?
The :!command syntax lets you execute any shell command directly from within Vim without leaving the editor.
category:
command-line
tags:
#command-line
#ex-commands
#editing
How do I search and replace text only on the current line?
The :s/old/new/g command replaces all occurrences of old with new on the current line only.
category:
search
tags:
#search
#ex-commands
#editing
How do I switch to the next buffer in Vim?
The :bnext (or :bn for short) command switches to the next buffer in Vim's buffer list.
category:
buffers-windows
tags:
#buffers
#ex-commands
#navigation
How do I open a file in a new tab in Vim?
The :tabnew filename command opens a file in a new tab page in Vim.
category:
buffers-windows
tags:
#buffers-windows
#tabs
#ex-commands
#navigation
How do I open a terminal inside Vim?
The :terminal command opens an interactive terminal emulator directly inside a Vim window.
category:
command-line
tags:
#command-line
#ex-commands
#buffers-windows
How do I switch to the previous buffer in Vim?
The :bprev (or :bp for short) command switches to the previous buffer in Vim's buffer list.
category:
buffers-windows
tags:
#buffers
#ex-commands
#navigation
How do I insert the output of a shell command into my file?
The :r !command command executes a shell command and inserts its output directly into the current buffer below the cursor line.
category:
command-line
tags:
#command-line
#ex-commands
#editing
How do I list all open buffers in Vim?
The :ls command displays a list of all open buffers in Vim, showing their buffer number, status indicators, file name, and the line the cursor was last on.
category:
buffers-windows
tags:
#buffers
#ex-commands
#navigation