Vim Keyboard Shortcuts

Learning Vim keyboard shortcuts can transform your text editing experience from tedious to efficient, making you a more productive developer or writer. Vim, famed for its steep learning curve and unparalleled editing capabilities, offers a wide array of keyboard shortcuts that can significantly enhance your workflow.

Whether you’re a novice just beginning to explore Vim’s powerful features or a seasoned user looking to fine-tune your skills, mastering these shortcuts will help you navigate, edit, and manipulate text with speed and precision.

In this article, we’re presenting an essential list of Vim keyboard shortcuts that can streamline your editing process and unleash the full potential of this robust text editor.

FAQ on Vim Keyboard Shortcuts

What is Vim?

Vim is a powerful, highly configurable text editor built for efficiency. It’s popular in programming due to its speed and versatility in editing code. Unlike typical editors, Vim has multiple modes like Normal, Insert, and Visual, allowing for complex text manipulation with minimal keystrokes.

How do I enter Insert mode in Vim?

To enter Insert mode, press i while in Normal mode. This allows you to insert text at the cursor position. Other keys like Ia, and A also switch modes but with slight variations. You’ll find Insert mode invaluable for straightforward text entry.

How can I save and exit in Vim?

Saving in Vim is straightforward. While in Normal mode, type :w to save your file. To exit, use :q. For a combined save and exit, :wq does the trick. Want to force it? Append ! to the commands, like :wq!. Vim’s command line mode makes this process seamless.

What are the basic movement commands in Vim?

Navigating text in Vim is about mastering simple keys. For basic movement, use h (left), j (down), k (up), and l (right). While w moves to the next word, b moves back. These commands turn text navigation into second nature, enhancing your editing speed.

How do I copy and paste text in Vim?

Cut, copy, and paste commands in Vim are quick. Use yy to copy (yank) a line, dd to cut, and p to paste after the cursor. For Visual mode, press v, select text, and use y or d followed by p. Clipboard management becomes intuitive with these shortcuts.

How can I undo and redo in Vim?

Mistakes aren’t fatal in Vim. Undo with u when in Normal mode. To redo, press Ctrl-r. These commands allow for efficient error correction, making edits reversible within seconds. Confidence in your work improves as you quickly rectify any slip-ups.

What are Vim’s different modes?

Vim operates in several modes. Normal mode is for commands; Insert mode is for typing text. Visual mode allows text selection, and Command-line mode (:) is for commands like saving. Mastering the switch between modes unlocks Vim’s full potential.

How do I search for text in Vim?

Searching in Vim is precise. Press / and type your query, hitting Enter to search forward. Use ? to search backward. Navigate results with n for next and N for previous. These search functionalities, enhanced by regex support, streamline code scanning.

How do I replace text in Vim?

Replacing text involves the :s command. For instance, :s/old/new replaces “old” with “new” in the current line. To replace globally, use :%s/old/new/g. This command can utilize regular expressions, allowing for sophisticated text substitutions effortlessly.

How do I customize Vim shortcuts?

Customizing Vim is simple with the .vimrc file. Map keys using commands like :map:noremap, or :imap for different modes. For example, adding noremap <C-A> :w<CR> in .vimrc maps Ctrl-A to save. Personalizing shortcuts optimizes your editing workflow.

And here’s the table with all the Vim keyboard shortcuts

KeysAction
:h[elp] keywordOpen help for keyword
:sav[eas] fileSave file as
:clo[se]Close current pane
:ter[minal]Open a terminal window
KOpen man page for word under the cursor
hMove cursor left
jMove cursor down
kMove cursor up
lMove cursor right
gjMove cursor down (multi-line text)
gkMove cursor up (multi-line text)
HMove to top of screen
MMove to middle of screen
LMove to bottom of screen
wJump forwards to the start of a word
WJump forwards to the start of a word (words can contain punctuation)
eJump forwards to the end of a word
EJump forwards to the end of a word (words can contain punctuation)
bJump backwards to the start of a word
BJump backwards to the start of a word (words can contain punctuation)
geJump backwards to the end of a word
gEJump backwards to the end of a word (words can contain punctuation)
%Move cursor to matching character
0Jump to the start of the line
^Jump to the first non-blank character of the line
$Jump to the end of the line
g_Jump to the last non-blank character of the line
ggGo to the first line of the document
GGo to the last line of the document
5gg or 5GGo to line 5
gdMove to local declaration
gDMove to global declaration
fxJump to next occurrence of character x
txJump to before next occurrence of character x
FxJump to the previous occurrence of character x
TxJump to after previous occurrence of character x
;Repeat previous f, t, F or T movement
,Repeat previous f, t, F or T movement, backwards
}Jump to next paragraph
{Jump to previous paragraph
zzCenter cursor on screen
ztPosition cursor on top of the screen
zbPosition cursor at the bottom of the screen
Ctrl + eMove screen down one line (without moving cursor)
Ctrl + yMove screen up one line (without moving cursor)
Ctrl + bMove screen up one page (cursor to last line)
Ctrl + fMove screen down one page (cursor to first line)
Ctrl + dMove cursor and screen down 1/2 page
Ctrl + uMove cursor and screen up 1/2 page
iInsert before the cursor
IInsert at the beginning of the line
aInsert (append) after the cursor
AInsert (append) at the end of the line
oAppend (open) a new line below the current line
OAppend (open) a new line above the current line
eaInsert (append) at the end of the word
Ctrl + hDelete the character before the cursor during insert mode
Ctrl + wDelete word before the cursor during insert mode
Ctrl + jAdd a line break at cursor position during insert mode
Ctrl + tIndent (move right) line one shiftwidth during insert mode
Ctrl + dDe-indent (move left) line one shiftwidth during insert mode
Ctrl + nInsert (auto-complete) next match before the cursor during insert mode
Ctrl + pInsert (auto-complete) previous match before the cursor during insert mode
Ctrl + rxInsert the contents of register x during insert mode
Ctrl + oxTemporarily enter normal mode to issue one normal-mode command x during insert mode
Esc or Ctrl + cExit insert mode
rReplace a single character
RReplace more than one character, until ESC is pressed
JJoin line below to the current one with one space in between
gJJoin line below to the current one without space in between
gwipReflow paragraph
g~Switch case up to motion
guChange to lowercase up to motion
gUChange to uppercase up to motion
ccChange (replace) entire line
c$ or CChange (replace) to the end of the line
ciwChange (replace) entire word
cw or ceChange (replace) to the end of the word
sDelete character and substitute text (same as cl)
SDelete line and substitute text (same as cc)
xpTranspose two letters (delete and paste)
uUndo
URestore (undo) last changed line
Ctrl + rRedo
.Repeat last command
vStart visual mode, mark lines, then do a command (like y-yank)
VStart linewise visual mode
oMove to the other end of marked area
Ctrl + vStart visual block mode
OMove to other corner of block
awMark a word
abA block with ()
aBA block with {}
atA block with <> tags
ibInner block with ()
iBInner block with {}
itInner block with <> tags
Esc or Ctrl + cExit visual mode
>Shift text right
<Shift text left
yYank (copy) marked text
dDelete marked text
~Switch case
uChange marked text to lowercase
UChange marked text to uppercase
:reg[isters]Show registers content
"xyYank into register x
"xpPaste contents of register x
"+yYank into the system clipboard register
"+pPaste from the system clipboard register
:marksList of marks
maSet current position for mark A
`aJump to position of mark A
ya“Yank text to position of mark A
`0Go to the position where Vim was previously exited
`"Go to the position when last editing this file
`.Go to the position of the last change in this file
``Go to the position before the last jump
:ju[mps]List of jumps
Ctrl + iGo to newer position in jump list
Ctrl + oGo to older position in jump list
:changesList of changes
g,Go to newer position in change list
g;Go to older position in change list
Ctrl + ]Jump to the tag under cursor
qaRecord macro a
qStop recording macro
@aRun macro a
@@Rerun last run macro
yyYank (copy) a line
2yyYank (copy) 2 lines
ywYank (copy) the characters of the word from the cursor to the start of the next word
yiwYank (copy) word under the cursor
yawYank (copy) word under the cursor and the space after or before it
y$ or YYank (copy) to end of line
pPut (paste) the clipboard after cursor
PPut (paste) before cursor
gpPut (paste) the clipboard after cursor and leave cursor after the new text
gPPut (paste) before cursor and leave cursor after the new text
ddDelete (cut) a line
2ddDelete (cut) 2 lines
dwDelete (cut) the characters of the word from the cursor to the start of the next word
diwDelete (cut) word under the cursor
dawDelete (cut) word under the cursor and the space after or before it
:3,5dDelete lines starting from 3 to 5
:g/{pattern}/dDelete all lines containing pattern
:g!/{pattern}/dDelete all lines not containing pattern
d$ or DDelete (cut) to the end of the line
xDelete (cut) character
>>Indent (move right) line one shiftwidth
<<De-indent (move left) line one shiftwidth
>%Indent a block with () or {} (cursor on brace)
<%De-indent a block with () or {} (cursor on brace)
>ibIndent inner block with ()
>atIndent a block with <> tags
3==Re-indent 3 lines
=%Re-indent a block with () or {} (cursor on brace)
=iBRe-indent inner block with {}
gg=GRe-indent entire buffer
]pPaste and adjust indent to current line
:wWrite (save) the file, but don’t exit
:w !sudo tee %Write out the current file using sudo
:wq or :x or ZZWrite (save) and quit
:qQuit (fails if there are unsaved changes)
:q! or ZQQuit and throw away unsaved changes
:wqaWrite (save) and quit on all tabs
/patternSearch for pattern
?patternSearch backward for pattern
\vpattern‘Very magic’ pattern: non-alphanumeric characters are interpreted as special regex symbols
nRepeat search in same direction
NRepeat search in opposite direction
:%s/old/new/gReplace all old with new throughout file
:%s/old/new/gcReplace all old with new throughout file with confirmations
:noh[lsearch]Remove highlighting of search matches
:vim[grep] /pattern/ {file}Search for pattern in multiple files
:cn[ext]Jump to the next match
:cp[revious]Jump to the previous match
:cope[n]Open a window containing the list of matches
:ccl[ose]Close the quickfix window
:tabnew or :tabnew {page.words.file}Open a file in a new tab
Ctrl + wTMove the current split window into its own tab
gt or :tabn[ext]Move to the next tab
gT or :tabp[revious]Move to the previous tab
#gtMove to tab number #
:tabm[ove] #Move current tab to the #th position (indexed from 0)
:tabc[lose]Close the current tab and all its windows
:tabo[nly]Close all tabs except for the current one
:tabdo commandRun the command on all tabs
:e[dit] fileEdit a file in a new buffer
:bn[ext]Go to the next buffer
:bp[revious]Go to the previous buffer
:bd[elete]Delete a buffer (close a file)
:b[uffer]#Go to a buffer by index #
:b[uffer] fileGo to a buffer by file
:ls or :buffersList all open buffers
:sp[lit] fileOpen a file in a new buffer and split window
:vs[plit] fileOpen a file in a new buffer and vertically split window
:vert[ical] ba[ll]Edit all buffers as vertical windows
:tab ba[ll]Edit all buffers as tabs
Ctrl + wsSplit window
Ctrl + wvSplit window vertically
Ctrl + wwSwitch windows
Ctrl + wqQuit a window
Ctrl + wxExchange current window with next one
Ctrl + w=Make all windows equal height & width
Ctrl + whMove cursor to the left window (vertical split)
Ctrl + wlMove cursor to the right window (vertical split)
Ctrl + wjMove cursor to the window below (horizontal split)
Ctrl + wkMove cursor to the window above (horizontal split)
Ctrl + wHMake current window full height at far left (leftmost vertical window)
Ctrl + wLMake current window full height at far right (rightmost vertical window)
Ctrl + wJMake current window full width at the very bottom (bottommost horizontal window)
Ctrl + wKMake current window full width at the very top (topmost horizontal window)
zfManually define a fold up to motion
zdDelete fold under the cursor
zaToggle fold under the cursor
zoOpen fold under the cursor
zcClose fold under the cursor
zrReduce (open) all folds by one level
zmFold more (close) all folds by one level
ziToggle folding functionality
]cJump to start of next change
[cJump to start of previous change
do or :diffg[et]Obtain (get) difference (from other buffer)
dp or :diffpu[t]Put difference (to other buffer)
:diffthisMake current window part of diff
:dif[fupdate]Update differences
:diffo[ff]Switch off diff mode for current window

In case the searchable table doesn’t load. 

 

7328cad6955456acd2d75390ea33aafa?s=250&d=mm&r=g Vim Keyboard Shortcuts
Related Posts