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 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 run the same Ex command in every open tab page at once?
The :tabdo {cmd} command executes an Ex command in each open tab page sequentially, visiting every tab and running the command there.
category:
buffers-windows
tags:
#tabs
#buffers
#ex-commands
#buffers-windows
How do I sort lines by a field in the middle or end of each line using a pattern?
The :sort r /{pattern}/ command sorts lines using the text that matches the pattern as the sort key.
category:
command-line
tags:
#command-line
#sorting
#ex-commands
#regex
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 control when Vim automatically wraps text or continues comment markers with formatoptions?
The formatoptions setting is a string of single-character flags that governs Vim's automatic text formatting: when lines wrap, whether comment syntax continues
category:
config
tags:
#config
#formatting
#ex-commands
#indentation
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 build a macro programmatically using Vimscript instead of recording it?
:call setreg('q', keys, 'c')
The setreg() function writes any string directly into a named register, letting you construct macro keystrokes from Vimscript expressions rather than live recor
category:
macros
tags:
#macros
#registers
#ex-commands
How do I create a mapping that does different things based on context?
nnoremap <expr> j (v:count == 0 ? 'gj' : 'j')
The map modifier turns a mapping's right-hand side into a Vimscript expression that is evaluated at the time the key is pressed, with its return value used as t
category:
config
tags:
#config
#normal-mode
#ex-commands
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 exclude compiled files and dependency folders from Vim's file name completion?
:set wildignore+=*.pyc,*.o,node_modules/**,.git/**
wildignore is a comma-separated list of glob patterns that Vim skips when expanding file names.
category:
config
tags:
#config
#ex-commands
#completion
How do I write a Vim regex that matches across multiple lines?
By default, .
category:
search
tags:
#search
#editing
#ex-commands
How do I refer to the current filename, extension, or directory in Vim ex commands?
Vim's filename modifiers let you derive path components from the current file's name directly inside ex commands.
category:
command-line
tags:
#command-line
#ex-commands
#buffers