How do I safely pass a Vim variable or the word under the cursor as an argument to a shell command?
The shellescape() function wraps a string in shell-safe quoting, escaping any special characters so it can be embedded in a shell command constructed with :exec
category:
command-line
tags:
#ex-commands
#command-line
#editing
#normal-mode
How do I delete each line matching a pattern along with a fixed number of lines that follow it?
Inside a :global command, .
category:
command-line
tags:
#ex-commands
#global
#delete
#editing
#command-line
How do I sort lines by a secondary field while ignoring a common leading prefix?
The :[range]sort /regex/ command sorts lines while skipping the portion of each line that matches the regex.
category:
command-line
tags:
#ex-commands
#sorting
#command-line
#search
How do I use the filename under the cursor as a value in a Vim mapping or command?
The expand('') function returns the filename that Vim sees under the cursor — the same file that gf would open.
category:
command-line
tags:
#command-line
#ex-commands
#navigation
#editing
#motions
How do I run an external command asynchronously from Neovim Lua and capture its output?
vim.system({cmd}, {opts}, callback)
vim.
category:
command-line
tags:
#command-line
#ex-commands
How do I restrict the :global command to operate on only a portion of the file?
:[range]g/pattern/command
The :global command accepts an optional line range prefix that restricts which lines it even considers matching.
category:
command-line
tags:
#command-line
#global
#ex-commands
#editing
How do I write an Ex range where the second address is evaluated relative to the first match instead of the cursor?
In Vim's range notation, a semicolon (;) between two addresses makes the second address relative to the line the first address matched, not to the current curso
category:
command-line
tags:
#command-line
#ex-commands
#search
#ranges
How do I join all soft-wrapped lines in each paragraph into a single line?
The :g/^.
category:
command-line
tags:
#command-line
#editing
#global
#formatting
#paragraphs
How do I populate the argument list with a glob pattern to work across multiple files?
The :args command sets Vim's argument list to all files matching a glob pattern.
category:
command-line
tags:
#command-line
#buffers
#ex-commands
#editing
How do I prevent Vim from pausing at the --More-- prompt when displaying long command output?
When a Vim command produces output that exceeds the terminal height, Vim pauses and displays a -- More -- prompt, requiring you to press a key to continue.
category:
config
tags:
#config
#command-line
#ex-commands
How do I open the directory containing the current file in netrw from within Vim?
The command :e %:h opens netrw (Vim's built-in file browser) in the directory that contains the current file.
category:
command-line
tags:
#command-line
#navigation
#buffers
#netrw
#editing
How do I execute Lua code directly from the Neovim command line without writing a script file?
Neovim's :lua command lets you run arbitrary Lua code inline from the command line.
category:
command-line
tags:
#command-line
#lua
#neovim
#vimscript
#advanced
How do I switch from typing a command to the full command-line window so I can edit it with all normal Vim keys?
<C-f> (from command-line)
When you are already in the middle of typing a command (after pressing :) and realize you need to compose something complex — a long substitution, a multi-pip
category:
command-line
tags:
#command-line
#editing
#normal-mode
How do I save a file with specific line endings in one command without changing the buffer's fileformat setting?
The ++ff modifier on :w forces the file format used for writing, independently of the buffer's 'fileformat' option.
category:
command-line
tags:
#ex-commands
#formatting
#command-line
#editing
How do I clear all entries from the quickfix list in Vim?
After a :grep, :make, or :vimgrep run, the quickfix list fills with results.
category:
command-line
tags:
#command-line
#buffers-windows
#quickfix
#ex-commands
How do I insert all Vim messages into the current buffer so I can read, search, or save them?
:put =execute('messages')
Vim's :messages command shows recent output — error messages, echo'd values, and diagnostic information — but the display is ephemeral and hard to search.
category:
registers
tags:
#registers
#ex-commands
#debugging
#command-line
How do I refer to all files in the argument list at once in an Ex command?
The ## special token expands to the names of all files currently in Vim's argument list.
category:
command-line
tags:
#command-line
#buffers
#ex-commands
#search
How do I sort lines in Vim without caring about upper or lower case?
By default, :sort uses byte-value ordering, which places all uppercase letters before lowercase.
category:
command-line
tags:
#editing
#ex-commands
#command-line
How do I sort lines while ignoring a leading prefix like a key or label?
The :sort /{pattern}/ command sorts lines by their content after the first match of the pattern.
category:
command-line
tags:
#editing
#ex-commands
#command-line
How do I create abbreviations for the Vim command line to fix typos like W and Q?
:cnoreabbrev defines a non-recursive command-line abbreviation — like noremap but for Ex commands.
category:
command-line
tags:
#command-line
#ex-commands
#config