Vim shortcut keys, and simple settings for VIMRC

Source: Internet
Author: User

s) The movement of the cursor
H Cursor moves to the beginning of the top line of the screen
M Cursor moves to the beginning of the middle line of the screen
L Cursor moves to the end of the last line of the screen

0 cursor moves to the beginning of the current line
$ Cursor moves to the end of the current line line
G Cursor moves to the beginning of the current line
GG cursor moves to the beginning of the first line
NG The cursor moves down n rows (including the current line) to the end of the line
n+ Move the cursor down n rows (including the current line) to the beginning of the line
N- Move the cursor up n rows (including the current line) to the beginning of the line
% first the cursor stays in "{" or "}" to move directly to another brace that matches the current curly brace


| Column
n| The cursor moves to the nth column of the current row


Note: Vim is case-sensitive, H is equivalent to shift + H, i.e. H and H are different commands!


Tips:
The movement of the cursor can be used with the Delete command and the copy-copy command!!
Such as:
D + 2 G is equivalent to deleting everything from the beginning of the cursor to the 2nd line
Y + 2 G is equivalent to copying everything from the beginning of the cursor to the 2nd line
D +% Delete all content in a block
Similarly: What is the role of D + GG and d+ g?


2) tumbling screen


Ctrl + u Tumbling half-screen to the top of the file
Ctrl + D Tumbling half-screen toward the end of the file
Ctrl + b Tumbling a screen to the top of the file
Ctrl + F Tumbling a screen toward the end of a file


Ctrl + G Lists the line number, file name, and%n of the line where the cursor is located
Ctrl + P Call plug-in Completion Word shortcut key pattern
Ctrl + R Recovery


3) Insert Text


I insert from the front of the cursor
I Insert from the beginning of the line where the cursor is located
A insert from the back of the cursor
A from the end of the line where the cursor is inserted
o Insert from the next line of the cursor (new row)
O Insert from the previous line of the cursor (new row)
R replaces the character at which the cursor is located
NR replaces the cursor and the following n characters
R enters the replacement state until the ESC end is pressed


Tip: Many beginners generally only use I, but I A O is also very important, can greatly reduce the number of times we move the cursor!!


4) Delete text


X Delete characters starting at the current position, including the characters indicated by the cursor
X forward deletes the character from the current position, without the character being referred to
Nx
Nx
d$ Delete to end of line
D0 Delete to the beginning of the line
Dw
Dn


Dd
Ndd


W) Copy sticky move


Yy
Nyy
yw
P


: N1, N2 CO n3 replication
: N1, N2 m n3 paste


N1 indicates which line, N2 represents the number of rows modified from N1 (including N1) a > represents a \ t
: N1 > N2
: N1 < N2
: N1 >> N2
: N1 << N2


6) Find and replace


/ Search from current position to end of file
? Search from current position to file start direction
N Continue searching in the same direction
N Continue looking in the opposite direction


The ground one that does not add a G to replace the row
: s/old/new
: s/old/new/g
N1,p2/old/new/g Replace all old N1 rows to N2 rows with new
: 0,$ s/old/new/g 0 and $ indicate from first line to last row
:%s/old/new/g % means all rows, plus g means replace all, no G replaces only the first of all rows


7) Undo and Redo


U Undo the previous command and go straight ahead.
U Fix a previous undo command
: Undo Undo the previous command
. Last input in duplicate edit state
Ctrl + R Undo the undo action you just made (Restore undo state)


8) Basic Bottom line command


: Q
: q!
: W
: w! Save read-only files, force save
: Wq
: X
Zz


: E file_name In the current VI file Central Europe opens a new file for you, the original file will be closed
: e! Load Reload the current file and the previous changes will be completely discarded
: New Open a new file, the original file will not be closed, pagination display


:! Execute shell command without leaving the VI environment
: N Jump to Nth row


9) Setting options
: Set All Show all the options currently
: Set Autoindent/noautoindent Auto Indent/No auto indent
: Set Ai/noai
Syntax on/off Syntax highlighting
Set St = 4
Set ts = 4


configuration file (hand party directly see this)


VI ~/.VIMRC (opens the current user's VIMRC profile first)


C + + style of the reduced format, with the following command to open the configuration file, the following English copy in, save Exit can


Set Cindent
Set Cinoptions={0,1s,t0,n-2,p2s, (03s,=.5s,>1s,=1s,:1s
Set Number "Show line number
Set tabstop=4
Set softtabstop=4
Set Autoindent
Set shiftwidth=4
If &term== "Xterm"
Set T_co=8
Set T_SB=^[[4%DM
Set T_SF=^[[3%DM
endif


10) More commonly used commands
S Modify the contents of the line where the cursor is located, the original content will be deleted
C Delete the contents of the line following the cursor and switch to the input state, such as 1234567, where the cursor remains only 123 after 4,s
K And! Act like
J Connect the row of the cursor with the next line of the cursor
: Split + file name Open another file, 2 files Common one window to horizontal split screen display

: Vplit + filename above, with vertical split screen display


Finally, send a picture of a relatively basic classic



Vim shortcut keys, and simple settings for VIMRC

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.