How do I sort lines by the text that matches a regex pattern rather than the text after it?
:sort r /pattern/
The :sort r /pattern/ command sorts lines using the matched portion of the regex as the sort key.
:sort r /pattern/
The :sort r /pattern/ command sorts lines using the matched portion of the regex as the sort key.
: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
:e +{cmd} {file}
The :e +{cmd} {file} form opens a file and executes an Ex command immediately after loading it.
%:p:h
Vim's filename modifiers let you derive path components from the current file's name directly inside ex commands.
:filter /pattern/ {command}
:filter /pattern/ {command} runs any Ex command but suppresses every output line that does not match the pattern.
:helpgrep
:helpgrep {pattern} searches all installed Vim help files for a pattern and populates the quickfix list with every match.
<C-\>e
Pressing e on the command line opens a special prompt that lets you type a Vimscript expression.
command-line #command-line #ex-commands #vimscript #insert-mode
:command
:command lets you define new Ex (colon-prefixed) commands with custom names, optional argument handling, and completion.
command-line #command-line #ex-commands #config #normal-mode
:cdo {cmd}
:cdo executes an Ex command on every entry in the quickfix list in sequence, visiting each match in turn.
<C-r><C-l>
Pressing on the command line inserts the full text of the current buffer line (the line the cursor is on when you pressed :) directly at the command-line cursor
:m.+1 and :m.-2
The :move (:m) command relocates a line to a new position without cutting and pasting.
:messages
:messages displays the full log of recent Vim messages — errors, warnings, echo output, and status notifications.
:e +/pattern filename
The +{cmd} flag on :edit (and most file-opening commands) runs an Ex command immediately after the file loads.
command-line #command-line #ex-commands #navigation #search #buffers
:execute
:execute evaluates a string as an Ex command, letting you build commands dynamically or embed special key sequences (like or ) as literal characters.
:put =system('cmd')
:put =system('cmd') lets you insert the output of any shell command as new lines in your buffer without leaving Vim.
:/pattern1/,/pattern2/
Ex command ranges in Vim are not limited to line numbers and marks — you can use /pattern/ as a range boundary to select lines between any two matching patter
:argdo %s/old/new/g | w
:argdo {cmd} executes an Ex command against every file in the argument list—the set of files you opened Vim with or set explicitly with :args.
:s/pattern/\=expr/g
Vim's :s command normally replaces matches with a literal string.
command-line #search #editing #ex-commands #command-line #registers
:s/pattern/\=expr/
Prefixing the replacement field of :s with \= makes Vim evaluate the rest as a Vimscript expression and use the result as the replacement string.
:e +{line} {file}
The :edit command accepts a +{cmd} prefix that executes an Ex command immediately after the file is loaded.
command-line #buffers #ex-commands #navigation #command-line