VIM common shortcut keys

1. Move the cursor

h,j,k,l left, down, up, right
ctrl-e move page
ctrl-f page up
ctrl-b page down
ctrl-u half page up
ctrl-d half page down
w Skip to next prefix, split by punctuation or word
W jumps to the beginning of the next word, long jump, such as end-of-line is considered a word
e skip to the next word ending
E jump to the next end of the word, long jump
b skip to previous word
B jump to the previous word, long jump
0 Jump to the beginning of the line, regardless of indentation, is to jump to the 0th character
^ jump to the first character at the beginning of the line
$ jump to end of line
gg Skip to beginning of text
G to end of text
5gg/5G to line 5
gd jumps to the declaration of the variable under the current cursor
fx find the x character in the current line, and jump to
; Repeat the last f command without repeatedly typing fx
 * Find the word where the cursor is, look down
# Find the word where the cursor is, look up

Second, delete the copy

dd delete the line where the cursor is located
dw delete a word (word)
d/D delete to the end of the line x delete the current character X delete the previous character yy copy a line yw copy a word y /D delete to the end of the line x delete the current character X delete the previous character yy copy a line yw copy a word y/Y copy to the end of the line
p pastes the contents of the pasteboard below the current line
P pastes the contents of the pasteboard above the current line

3. Insert mode

i enter insert mode from the current cursor
I enter insert mode and place the cursor at the beginning of the line
a Append mode, place the cursor after the current cursor
A Append mode, place the cursor at the end of the line
o Add a new line below the current line and enter insert mode
O adds a new line above the current line and enters insert mode
Esc to exit insert mode

4. Editing

J joins the next line and the current line into one line
cc delete the current line and enter edit mode
cw delete the current word and enter edit mode
c$ Erase the content from the current position to the end of the line and enter edit mode
s delete the current character and enter edit mode
S delete the line where the cursor is and enter edit mode
xp swaps the current character and the next character
u Cancel
ctrl+r redo
~ switch case, current character
>> move the current line one unit to the right
<< Move the current line to the left by one unit (a tab character)
 == automatically indents the current line

Five, find and replace

/pattern searches backwards for the string pattern
?pattern searches the string pattern forward
"\c" ignore case
"\C" is case sensitive
n next match (if /search, next down, ?search is next up)
N previous match (same as above)
:%s/old/new/g searches the entire file and replaces all old with new
:%s/old/new/gc Search the entire file, replace all old with new, and ask you to confirm whether to replace each time

6. Exit the editor

:w writes the buffer to the file, i.e. saves the changes
:wq save changes and exit
:x save changes and exit
:q quit, if the buffer has been modified, it will prompt
:q! Force quit, discard changes

Seven, multi-file editing

vim file1.. open multiple files at the same time
:args show the currently edited file
:next switch to the next file
:prev switch to the previous file
:next! Do not save the current edited file and switch to the next file
:prev! Do not save the current edited file and switch to the previous file
:wnext saves the current edited file and switches to the next file
:wprev save the current edited file and switch to the previous file
:first locate the first file
:last locates the last file
ctrl+^ Quickly switch between the two most recently opened files
:split[sp] split the current file horizontally
:split file splits the current window horizontally, file
:vsplit[vsp] file splits the current window vertically, file
:new file 同split file
:close closes the current window
:only show only the current window, close all other windows
:all open all windows
:vertical all open all windows, open vertically
:qall performs the :q operation on all windows
:qall! performs the :q! operation on all windows
:wall performs the :w operation on all windows
:wqall performs the :wq operation on all windows
ctrl-w h jump to the left window
ctrl-w j jump to the window below
ctrl-w k jump to the window above
ctrl-w l jump to the right window
ctrl-w t jump to the top window
ctrl-w b jump to the bottom window

Eight, multi-label editing

:tabedit file opens the file file in a new tab
:tab split file opens the file file in a new tab
:tabp switch to previous tab
:tabn switch to the next tab
:tabc closes the current tab
:tabo close other tabs
gt go to next tab
gT to the previous tab
0gt jump to the first tab
5gt jump to the fifth tab

9. Execute shell commands

1. Enter ":sh" in command mode, you can run it in character mode, when you want to return to the VIM editor at the end of the input, use exit, ctrl+D to return to the VIM editor
2. You can use "!command" to automatically return to the VIM editor after running
3. Use "Ctrl+Z" to return to the shell, and use fg to return to editing
4. :!make -> run the make command directly in the current directory

10. VIM startup items

-o[n] Open multiple files in horizontal split screen
-O[n] Open multiple files in vertical split screen

Eleven, automatic typesetting

After pasting some code, vim gets messy, just execute gg=G and it will be done

12. How to compile programs in vim

Make can be done in vim, and the result of compilation can also be displayed in vim, first execute the :copen command, open the window of the result output, and then execute: make
The compiled result is displayed in the small window opened by capen, and double-clicking the error message with the mouse will jump to the line where the error occurred.

Thirteen, buffer operation

1. Buffer status
- (inactive buffer)
a (currently activated buffer)
h (hidden buffer)
% (current buffer)
# (swap buffer)
= (read-only buffer)
+ (changed buffer)

14. VIM operation directory

1. Open the directory
vim .
 vim a-path/

2. The following operations take effect when operating the directory
p,P,t,u,U,x,v,o,r,s

c make the currently open directory the current directory
d create a directory
% Create a file
D delete file/directory
- go to upper directory
gb go to the previous bookmarked directory
 i Change the way the directory file is listed
^l refresh the currently open directory

mf - tag file
mu - unmark all marked files
mz - Compress/decompress marked files
gh show/do not show hidden files (dot-files)
^h edit hidden file list
a switch display mode, all - hide - unhide
qf diplay infomation about file
qb list the bookmarked directories and directory traversal history
gi Display information on file

mb
mc
md - use diff mode for marked files (mf marked files)
me - edit the marked files, only one is displayed, the rest are put into the buffer
mh
mm - move marked files to marked-file target directory
mc - copy
mp
mr
mt

Copy and move files in vim
1, mt - directory to move to
2, mf - mark files to move
3, mc - move/copy

R move files

Open the directory of the currently edited file
:Explore
:Hexplore
:Nexplore
:Pexplore
:Sexplore
:explore
:explore


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324884138&siteId=291194637