How do I pipe the contents of my current buffer as input to a shell command in Vim?
:w !cmd
The :w !cmd command sends the buffer's contents as standard input to an external command without modifying the buffer.
:w !cmd
The :w !cmd command sends the buffer's contents as standard input to an external command without modifying the buffer.
ea
The ea compound shortcut moves to the last character of the current word with e, then enters insert mode after the cursor with a.
do
The do command (diff obtain) is shorthand for :diffget.
<C-f> (in command-line mode)
When you're already on the Vim command line and realize you need complex edits — inserting text from multiple positions, reordering arguments, or referencing
<C-r><C-r>x
When you press x in insert mode to paste a register, Vim inserts the text "as if you typed it" — meaning autoindent, textwidth, and other insert behaviors can
gUU
The gUU command uppercases every character on the current line instantly — no visual selection or motion required.
:%s/\n/ /g
Using \n in the pattern of :substitute matches the newline character at the end of each line, letting you join lines with any separator you choose — something
:g/^\s*$/d
The global command :g/^\s$/d removes every line that is empty or contains only whitespace — a common cleanup task when tidying up code, configuration files, o
\n in search, \r in replacement
Vim uses \n and \r differently depending on whether they appear in a search pattern or a replacement string, and mixing them up is a common source of confusion.
:set nomodifiable
:set nomodifiable locks a buffer so that no changes can be made at all — not even temporary ones.
:set formatprg=<cmd>
When formatprg is set, the gq operator pipes the selected text through that external program and replaces it with the program's output.
it and at
Vim provides two built-in text objects for HTML and XML tags: it (inner tag) and at (a tag).
editing #text-objects #editing #visual-mode #html #normal-mode
%:e
Vim exposes the current filename as % in Ex commands, and you can apply modifiers to extract specific parts of the path.
:let @a .= "text"
Vim registers are just strings, and you can read and write them directly using the :let command.
zG
zG marks the word under the cursor as correctly spelled in Vim's internal word list, which exists only for the current session.
:diffoff!
The :diffoff! command exits diff mode in every window simultaneously.
<C-w>P
The preview window is a special auxiliary split — usually at the top — opened by commands like :ptag, :pedit, and omni-completion to display reference infor
<C-c>
exits insert mode immediately but silently skips two important side effects that (and its equivalent ) always trigger: abbreviation expansion and InsertLeave au
[e and ]e
The [e and ]e mappings from Tim Pope's vim-unimpaired plugin exchange the current line (or a visual selection of lines) with the line above or below.
cs{from}{to}
The cs command from the vim-surround plugin lets you swap one type of surrounding delimiter for another in a single motion.