小狼阳帆

WolfYangFan Blog

你好,我是小狼阳帆,很高兴认识你!
email
misskey

Commonly Used Vim Commands/Shortcuts Quick Reference Guide

This article lists the most commonly used commands and shortcuts in Vim (not all), please make good use of the search.

Vim Keymap

Vim Keymap

Global Commands#

Command / ShortcutFunction Description
elp keywordDisplay help for the specified keyword
eas filenameSave as...
seClose the current window
minalOpen a new terminal window
:! commandTemporarily leave Vim to execute command in the command line and display the result
KOpen the man page for the word under the cursor

Move Cursor#

Command / ShortcutFunction Description
hMove cursor left
jMove cursor down
kMove cursor up
lMove cursor right
HMove to the top of the current page
MMove to the middle of the current page
LMove to the bottom of the current page
wMove to the beginning of the next word
WMove to the beginning of the next word (including punctuation)
eMove to the end of the next word
EMove to the end of the next word (including punctuation)
bMove to the beginning of the previous word
BMove to the beginning of the previous word (including punctuation)
%Jump to the matching symbol
0Move to the beginning of the line
^Move to the first non-blank character of the line
$Move to the end of the line
}Move to the next paragraph (or function/code block when editing code)
{Move to the previous paragraph (or function/code block when editing code)
zzCenter the cursor on the screen
Ctrl + eScroll down one line (keeping the cursor in place)
Ctrl + yScroll up one line (keeping the cursor in place)
Ctrl + bScroll up one screen
Ctrl + fScroll down one screen
Ctrl + dScroll down half a screen
Ctrl + uScroll up half a screen

Insert Mode#

Command / ShortcutFunction Description
iStart inserting characters from before the cursor
IStart inserting characters from the beginning of the line
aStart inserting characters from after the cursor
AStart inserting characters from the end of the line
oStart a new line below the current line and begin inserting characters
OStart a new line above the current line and begin inserting characters
eaStart inserting from the end of the current word
Ctrl + hDelete the character before the cursor in insert mode
Ctrl + wDelete the word before the cursor in insert mode
Ctrl + jStart a new line in insert mode
Ctrl + tIndent right in insert mode, width controlled by shiftwidth
Ctrl + dIndent left in insert mode, width controlled by shiftwidth
Ctrl + nInsert the next match of auto-completion before the cursor in insert mode
Ctrl + pInsert the previous match of auto-completion before the cursor in insert mode
Ctrl + rxInsert the contents of register x at the current cursor position
EscExit insert mode

Edit Text#

Command / ShortcutFunction Description
uundo - Undo the last operation
URestore/undo the last modified line
Ctrl + rredo - Redo (opposite of u)
.Repeat the last command

Select Text and Visual Mode#

Command / ShortcutFunction Description
vEnter visual mode, move the cursor to highlight selection, then execute commands on the selected text
VEnter visual mode, select by line
oIn visual mode, toggle the cursor between the start and end of the selection
OIn visual mode, toggle the cursor to the corners of the selection
Ctrl + vEnter visual mode, block selection (i.e., column mode)
awIn visual mode, select the current word
abIn visual mode, select the content wrapped in () (including parentheses)
aBIn visual mode, select the content wrapped in {} (including braces)
atIn visual mode, select the content wrapped in <> (including <> tags)
ibIn visual mode, select the content wrapped in () (excluding parentheses)
iBIn visual mode, select the content wrapped in {} (excluding braces)
itIn visual mode, select the content wrapped in <> (excluding <> tags)
EscExit visual mode
>Indent right
<Indent left
yCopy the selected text
dCut the selected text
~Toggle the case of the selected text
uConvert the selected text to lowercase
UConvert the selected text to uppercase

Exit#

Command / ShortcutFunction Description
Write the edited data to disk (save)
!Force write the file if it is read-only
!sudo tee %Save the current file using sudo
or or ZZSave and exit
Exit (Vim will warn if the file has been modified and not saved)
! or ZQForce exit (even if the file is not saved, equivalent to force exit)
Save all tabs and exit

Vim Modes#

ModeEntering Method
Normal ModeEnter by pressing Esc or Ctrl+[; filename or empty at the bottom left
Insert ModeEnter by pressing i; --INSERT-- at the bottom left
Visual ModeEnter by pressing v; --VISUAL-- at the bottom left
Replace ModeStart by pressing r or R; --REPLACE-- at the bottom left
Command Line ModeStart by pressing : or / or ?

References#

Bored Space - vi Quick Reference

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.