VIM HotKey Cheatsheet

2024 年 12 月 19 日

VIM is a powerful text editor widely used in programming and daily editing tasks. It supports multiple operating systems and is known for its efficient keyboard shortcuts. By mastering these shortcuts, users can significantly improve editing efficiency.

VIM Linux Shortcuts

Editing Functions

ShortcutFunction Description
iEnter insert mode, insert text before the cursor
IEnter insert mode, insert text at the beginning of the current line
aEnter insert mode, insert text after the cursor
AEnter insert mode, insert text at the end of the current line
oInsert a new line below the current line and enter insert mode
OInsert a new line above the current line and enter insert mode
xDelete the character at the cursor's position
ddDelete the current line
yyCopy the current line
pPaste the copied or cut content
uUndo the last action
Ctrl + rRedo the last undone action

Navigation Functions

ShortcutFunction Description
hMove the cursor one character left
jMove the cursor one line down
kMove the cursor one line up
lMove the cursor one character right
wJump to the beginning of the next word
bJump to the beginning of the previous word
0Jump to the beginning of the current line
$Jump to the end of the current line
GJump to the last line of the file
ggJump to the first line of the file
Ctrl + fScroll down one page
Ctrl + bScroll up one page

Search and Replace Functions

ShortcutFunction Description
/Start search and input the text to search
nFind the next match
NFind the previous match
:%s/old/new/gReplace all occurrences of "old" with "new" in the file
:s/old/new/gReplace all occurrences of "old" with "new" in the current line

File Operations

ShortcutFunction Description
:wSave the file
:qQuit the VIM editor
:wqSave the file and quit the VIM editor
:xSave the file and quit the VIM editor (same as :wq)
:q!Quit without saving
:e filenameOpen the file "filename"
:saveas filenameSave the current file as "filename"

Display and Window Operations

ShortcutFunction Description
Ctrl + w + sSplit the window and open a new window below
Ctrl + w + vSplit the window and open a new window to the right
Ctrl + w + qClose the current window
Ctrl + w + hSwitch to the left window
Ctrl + w + lSwitch to the right window
Ctrl + w + kSwitch to the upper window
Ctrl + w + jSwitch to the lower window

Download VIM Linux Shortcuts Cheatsheet PDF

We provide a VIM Linux Shortcuts PDF download feature. Click the download button to get the file. Please note that generating the PDF may take some time, so please be patient. Download

About VIM

VIM is a full-featured text editor commonly used in programming, system administration, and everyday text editing tasks. Its name comes from "Vi IMproved," an improved version of Vi. VIM supports almost all operating systems and is the default editor in many Linux systems. The most distinctive feature of VIM is its keyboard shortcuts, allowing users to efficiently edit in different modes such as command mode, insert mode, and visual mode.

VIM offers powerful search and replace functions, supports regular expressions, and can be extended with plugins. It can handle nearly all text editing tasks and even replace more complex IDEs.

VIM Official Website Information

Common VIM Shortcut Questions

  1. How to exit the VIM editor?
    In command mode, type :q to exit. If the file is unsaved, use :q! to force exit. To save and exit, type :wq.

  2. How to switch modes in VIM?
    VIM has three main modes: command mode, insert mode, and visual mode. Press Esc to return to command mode; press i to enter insert mode; press v to enter visual mode.

  3. Does VIM support multi-file editing?
    Yes, VIM supports opening multiple files in different tabs or windows. You can open other files using the :e command or create a new tab with :tabnew.

  4. How to perform batch replacement?
    In command mode, use :%s/old/new/g to replace all occurrences of "old" with "new."

Conclusion

VIM is a powerful text editor with many shortcuts that help users improve efficiency. By mastering the common VIM shortcuts, users can be more proficient in editing code and documents. I hope the shortcut summary provided in this article will help you better understand and use the VIM editor, boosting your work efficiency. If you are a VIM beginner, start with these basic shortcuts and gradually master more advanced features.

4.5/5 - (2 votes)