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).
:botright split
When you split a window with :split or :vsplit, Vim subdivides only the current window.
buffers-windows #buffers #windows #ex-commands #command-line
: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
: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.
:let @a = "content"
When a recorded macro has a typo or needs a small tweak, you don't have to re-record it entirely.
"/
Vim stores the last search pattern in the special / register.
: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
:%!
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
:'<,'>!sort -t',' -k2 -n
Vim does not have a built-in multi-column sort, but you can leverage the external sort command to sort selected lines by any field.
editing #editing #sorting #ex-commands #external-commands #command-line
: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
:set wildmenu wildmode=longest:full,full
By default, Vim's command-line tab completion just cycles through options.
:keeppattern s/old/new/g
When you run a :s or :g command, Vim updates the search register (@/) with the pattern you used.
:g/pattern/z#.5
The :global command is great for finding lines matching a pattern, but by default it only shows the matching lines themselves.