How do I extract the directory, filename, or extension from the current file path inside a Vim command?
%:h
Vim's filename modifiers let you derive path components from the current buffer's filename directly on the command line.
%:h
Vim's filename modifiers let you derive path components from the current buffer's filename directly on the command line.
<C-y> and <C-e>
In Insert mode, copies the character at the same column position from the line above the cursor, and copies the character from the line below.
:cdo s/old/new/ | update
:cdo {cmd} executes a command at every entry in the quickfix list, visiting each location in turn.
:'<,'>norm I//
After making a visual selection, :norm {commands} executes normal-mode keystrokes on every line in the range.
:noautocmd write
The :noautocmd modifier (abbreviated :noa) runs any subsequent Ex command while temporarily disabling all autocommand events.
:%s/pattern/\U&/g
Vim's substitute replacement string supports special case-transform atoms that change the case of matched text without requiring a second pass or an external to
:let @a = "content"
When a recorded macro has a typo or needs a small tweak, you don't have to re-record it entirely.
<C-a> (insert mode)
While in insert mode, pressing re-inserts the exact text you typed during your previous insert session.
:keeppatterns
Normally, any command that uses a pattern — including :substitute, :global, and :vimgrep — replaces the current search register @/ with the new pattern.
"-
Vim silently stores every deletion of less than one line in the special "- register (the "small delete" register).
:earlier
Vim's undo history is not just a linear list of changes — it records timestamps too.
:find
The :find command searches for a file by name across all directories listed in Vim's path option, so you can open files without typing full paths.
!{motion}{command}
The ! operator filters the text covered by a motion through an external shell command, replacing the original lines with the command's stdout.
@"
Vim macros are stored in registers — and you can execute any register as a macro with @{register}.
: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.
[p
When you copy code from one indentation level and paste it at another, p preserves the original indentation, leaving your code misaligned.
:argdo norm @a | update
Combining :argdo with :norm @a lets you apply a recorded macro to every file in Vim's argument list — a powerful pattern for bulk refactoring across a project
<C-x>s
When spell checking is enabled (:set spell), s in insert mode opens a popup menu of suggested corrections for the most recently flagged misspelled word — with
:%!
The ! operator pipes text through a shell command, replacing the selected lines with the command's output.