How do I make Vim remove the comment leader from the second line when joining two comment lines?
Adding the j flag to formatoptions causes Vim to strip the comment leader from the second line when two comment lines are joined with J.
category:
config
tags:
#editing
#formatting
#config
#ex-commands
How do I open all nested folds under the cursor at once in Vim?
zO (uppercase O) opens the fold under the cursor and all folds nested inside it recursively.
category:
editing
tags:
#folding
#editing
#normal-mode
How do I center, right-justify, or left-justify lines of text in Vim without a plugin?
:'<,'>center / :'<,'>right / :'<,'>left
Vim has built-in Ex commands to align text within a specified width: :center, :right, and :left.
category:
editing
tags:
#editing
#visual-mode
#formatting
#ex-commands
How do I convert variable names between snake_case, camelCase, and other naming conventions with vim-abolish?
The vim-abolish plugin adds coercion operators that instantly convert the word under the cursor between common naming conventions.
category:
plugins
tags:
#editing
#text-objects
#plugins
#normal-mode
#formatting
How do I delete, change, or yank an entire sentence as a text object in Vim?
Vim defines a sentence as text ending with .
category:
editing
tags:
#editing
#text-objects
#delete
#normal-mode
#motions
How do I make Ctrl-A and Ctrl-X increment and decrement hexadecimal numbers?
By adding hex to the nrformats option, you tell Vim to recognise hexadecimal literals such as 0xFF or 0xDEAD when or is pressed.
category:
config
tags:
#config
#numbers
#increment
#normal-mode
#editing
How do I get a more accurate diff that avoids matching unrelated lines?
:set diffopt+=algorithm:histogram
Switches Vim's diff algorithm from the default Myers algorithm to histogram, which produces more semantically meaningful diffs by avoiding false matches between
category:
config
tags:
#diff
#config
#buffers
#editing
How do I stop Vim from automatically continuing comment markers when I press Enter or open a new line?
By default, Vim continues the current comment leader when you press in insert mode or open a new line with o/O.
category:
config
tags:
#config
#editing
#formatting
#ex-commands
How do I change the case of captured text in a :substitute replacement?
\u / \l / \U / \L (in :s replacement)
Vim's :substitute replacement string supports case-conversion modifiers that let you uppercase or lowercase matched text without writing a separate command.
category:
search
tags:
#search
#editing
#ex-commands
#normal-mode
How do I join a specific range of lines into one line using an Ex command?
The :[range]join Ex command lets you join lines by specifying an explicit line range — without having to navigate there or use visual selection.
category:
editing
tags:
#ex-commands
#editing
#formatting
#normal-mode
How do I center or right-align a range of lines in Vim?
:[range]center / :[range]right / :[range]left
Vim has built-in Ex commands for text alignment: :center, :right, and :left.
category:
command-line
tags:
#ex-commands
#editing
#formatting
#visual-mode
How do I sort lines by the text that matches a regex pattern rather than the text after it?
The :sort r /pattern/ command sorts lines using the matched portion of the regex as the sort key.
category:
command-line
tags:
#ex-commands
#search
#editing
#normal-mode
How do I generate multiple lines of text using a Vimscript for loop from the command line?
:for i in range(1,5) | put ='item '.i | endfor
Vimscript's for loop is available directly from Vim's command line and can be used to generate repetitive or parameterized text without a macro or external scri
category:
command-line
tags:
#ex-commands
#macros
#editing
#normal-mode
How do I open a file and immediately execute a command, like jumping to a pattern or line?
The :e +{cmd} {file} form opens a file and executes an Ex command immediately after loading it.
category:
command-line
tags:
#ex-commands
#buffers
#editing
How do I remove Windows carriage returns (^M) from a file opened in Vim?
When a file created on Windows is opened in Vim on a Unix system, lines may retain \r (carriage return) characters, displayed as ^M at the end of each line.
category:
editing
tags:
#editing
#search
#ex-commands
#normal-mode
How do I center-align or right-align lines of text in Vim without an external tool?
Vim's built-in :left, :center, and :right Ex commands align text without plugins or external tools.
category:
editing
tags:
#editing
#ex-commands
#formatting
How do I prevent cursor movement in insert mode from splitting the undo block?
inoremap <Left> <C-g>U<Left>
In insert mode, any cursor movement — including arrow keys, Home, and End — causes Vim to split the undo block at that point.
category:
editing
tags:
#insert-mode
#undo-redo
#editing
How do I copy the contents of one register into another register?
Vim's :let command lets you read and write register contents as strings, making it possible to copy, combine, or modify register values without ever leaving the
category:
registers
tags:
#registers
#ex-commands
#editing
#normal-mode
How do I insert the same text at the start (or end) of multiple lines simultaneously?
<C-v>{motion}I{text}<Esc>
Visual block mode () lets you select a rectangular region across multiple lines.
category:
visual-mode
tags:
#visual-mode
#editing
#normal-mode
How do I open the previous file I was editing in a split window?
In Vim, # is a special filename that always refers to the alternate file — the most recently active buffer before the current one.
category:
buffers-windows
tags:
#buffers
#windows
#navigation
#editing