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 make netrw display files in a tree-style directory listing?
:let g:netrw_liststyle = 3
By default, netrw shows files in a flat listing.
category:
plugins
tags:
#netrw
#file-browser
#plugins
#configuration
#built-in
How do I rename files directly from Vim's built-in netrw file browser?
Vim's built-in file explorer netrw lets you rename files and directories without leaving the editor.
category:
plugins
tags:
#netrw
#file-management
#plugins
#rename
#built-in
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 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 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 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 write a Vim search pattern that matches text spanning multiple lines?
Vim's regex engine normally treats .
category:
search
tags:
#search
#regex
#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
How do I write a Vim regex that matches across multiple lines?
By default, .
category:
search
tags:
#search
#editing
#ex-commands