How do I open a related file with a different extension using the current filename?
:e %:r.html
In Vim's command line, % expands to the current buffer's filename.
command-line #ex-commands #command-line #buffers #navigation
:e %:r.html
In Vim's command line, % expands to the current buffer's filename.
command-line #ex-commands #command-line #buffers #navigation
<C-r><C-a>
When you are in command-line mode, inserts the word under the cursor (alphanumeric and _ only).
:history
:history displays a numbered list of your recently entered Ex commands, giving you a full audit of what you have run in the current session (and across sessions
:cdo
:cdo {cmd} executes {cmd} on each entry in the quickfix list — one by one, jumping to each location in turn.
command-line #ex-commands #quickfix #search #editing #buffers
:sort /regex/
The :sort /pattern/ command sorts lines by the text that appears after the first match of a pattern, not from the start of each line.
:s/pattern//gn
The :s///gn command counts how many times a pattern appears in the file without actually replacing anything.
command-line #search #ex-commands #substitution #command-line
:.!{cmd}
:.
%:h
Vim's filename modifiers let you derive path components from the current buffer's filename directly on the command line.
:cdo s/old/new/ | update
:cdo {cmd} executes a command at every entry in the quickfix list, visiting each location in turn.
:noautocmd write
The :noautocmd modifier (abbreviated :noa) runs any subsequent Ex command while temporarily disabling all autocommand events.
:keeppatterns
Normally, any command that uses a pattern — including :substitute, :global, and :vimgrep — replaces the current search register @/ with the new pattern.
:keeppatterns %s/old/new/g
The :keeppatterns modifier runs any Ex command without modifying Vim's last search pattern (stored in @/).
command-line #search #ex-commands #command-line #substitute #registers
:norm
:normal (abbreviated :norm) executes a sequence of normal-mode keystrokes on each line of an address range.
:t
The :t command (short for :copy) copies addressed lines to a destination line number, leaving the unnamed register untouched.
:%!
The ! operator pipes text through a shell command, replacing the selected lines with the command's output.
:keeppatterns {command}
The :keeppatterns modifier runs an Ex command — typically :s, :g, or :v — without modifying @/ (the last search pattern) or the command history.
command-line #ex-commands #search #substitution #command-line #scripting
:wall
When working across multiple files, you often have unsaved changes in several buffers.
:let view=winsaveview() | {cmd} | call winrestview(view)
When writing Vimscript functions or mappings, commands like :substitute, gg, or :%normal will move the cursor and change the scroll position.
:sandbox {cmd}
The :sandbox command modifier executes any Ex command in a restricted environment where potentially dangerous operations are blocked.
:g/pattern/m0
When working with large files, you sometimes need to reorganize content by pulling all lines matching a certain pattern to the top.
command-line #global #move #ex-commands #editing #command-line