How do I execute the contents of a register as an Ex command?
:@a
How it works The command :@a executes the contents of register a as an Ex command.
1029 results for "i" a""
:@a
How it works The command :@a executes the contents of register a as an Ex command.
:let @a=getline('.')<CR>@a
How it works Instead of recording keystrokes interactively, you can write a sequence of Vim commands as plain text in your buffer and then execute that text as
:w !sudo tee %
The :w !sudo tee % command lets you save a file that requires root permissions, even if you forgot to open Vim with sudo.
:let @q = "dwelp"
Recording macros with q works well for simple sequences, but complex macros with special keys can be hard to get right in one take.
:cnoremap <C-a> <Home>
Vim's command line has limited navigation by default.
:'<,'>normal @a
The :'normal @a command executes the macro stored in register a on every line within the current visual selection.
/pattern\@!
The \@! atom is a negative lookahead in Vim regex.
"=2+3<CR>p
The expression register = evaluates a Vimscript expression and stores the result.
:Git command (e.g., :Git status)
vim-fugitive by Tim Pope is a comprehensive Git wrapper for Vim.
:%!tac
Vim doesn't have a built-in reverse command, but you can pipe the buffer through tac (reverse of cat) to flip line order.
qaq qa...@aq @a
A recursive macro calls itself at the end of its recording, causing it to repeat indefinitely until a command inside it fails (like a search hitting the end of
O
The O (uppercase) command opens a new blank line above the current line and places you in insert mode, ready to type.
S"
The vim-surround plugin provides the S command in visual mode to wrap any selection with a delimiter pair.
:match {group} /{pattern}/
:match lets you apply a highlight group to any pattern in the current window without touching the buffer or its syntax rules.
:let @q then use in nnoremap
Macros are stored in registers as plain keystroke strings.
Va{ or Vi{
The a{ (around braces) and i{ (inside braces) text objects combined with visual mode let you instantly select an entire function body or code block, regardless
visual-mode #visual-mode #text-objects #code-navigation #selection
:WhichKey
which-key.
\%l and \%c
Vim's \%l and \%c pattern atoms anchor a search to a particular line number or column, enabling surgical searches and substitutions that standard regex cannot e
:tab sb N
How it works The :tab sb N command opens buffer number N in a brand new tab page.
100@a
When you give a large count to a macro — such as 100@a — Vim automatically stops replaying the macro as soon as any step inside it fails.