How do I programmatically simulate keypresses in Vim?
:call feedkeys("iHello\<Esc>", 'n')
The feedkeys() function injects keystrokes into Vim's input buffer as if the user typed them.
210 results for "insert mode"
:call feedkeys("iHello\<Esc>", 'n')
The feedkeys() function injects keystrokes into Vim's input buffer as if the user typed them.
<C-v>j$A;<Esc>
When lines have varying lengths, a normal visual block selection stops at the shortest line.
dit
The dit command deletes the text inside the nearest enclosing HTML or XML tag pair without removing the tags themselves.
:verbose nmap <leader>
The :verbose prefix on mapping commands shows not just the mapping definition but also the file and line number where it was defined.
<Leader>tm
The vim-table-mode plugin by Dhruva Sagar turns Vim into a powerful table editor that automatically formats and aligns table columns as you type.
{count}{motion}
Almost every Vim motion and operator accepts a numeric count prefix that repeats or amplifies the action.
:%norm A;
The :%norm command runs normal mode commands on every line in the file (or a range).
vas
The vas command visually selects the current sentence, including surrounding whitespace.
:%normal @q
To apply a macro to every line in the file, use :%normal @q.
qq;.q then @q or @@
The dot command (.
:set conceallevel=2
The conceallevel option controls how Vim displays characters that have the "conceal" syntax attribute.
:set foldmethod=marker
Setting foldmethod=marker lets you define fold boundaries using special comment markers — {{{ to start a fold and }}} to end it.
:s/\d\+/\=submatch(0)+1/g
The \= prefix in a :substitute replacement field tells Vim to evaluate the following as a Vimscript expression rather than treating it as a literal string.
de
The de command deletes from the cursor position to the end of the current word.
"ap, edit, 0"ay$
When a macro has a small mistake, re-recording the entire thing is tedious.
:s/,/,\r/g
In Vim's :substitute command, \r in the replacement string inserts a literal newline — it splits the line at that point.
:'<,'>normal A;
The :normal command executes normal-mode keystrokes on every line in a range.
command-line #command-line #ex-commands #editing #normal-mode #batch-editing
:let @a = "value"
The :let @{reg} = expr command lets you assign any string or expression directly into a named register without entering insert mode or performing a yank.
:cabbrev
:cabbrev (command-line abbreviation) lets you define short aliases for longer Ex commands.
:.!{cmd}
:.