A summary of the quick operation of Vim under Linux

Source: Internet
Author: User

How to move the cursor

h or LEFT ARROW key (←) The cursor moves one character to the left
J or DOWN ARROW key (↓) cursor moves down one character
K or Up ARROW key (↑) The cursor moves up one character
L or right ARROW key (→) The cursor moves one character to the right

[Ctrl] + [f] screen "down" to move one page, equivalent to [PAGE DOWN] key (common)
[Ctrl] + [b] screen "Up" move one page, equivalent to [PAGE UP] key (common)
[Ctrl] + [d] screen "down" move half page
[Ctrl] + [u] screen "Up" move half page
+ cursor moves to the next column of non-whitespace
-Cursor moves to the previous column of non-whitespace
N<space> that n means "number", for example 20. When you press the number and then press the SPACEBAR, the cursor moves the n characters of the line to the right. For example 20<space>, the cursor moves 20 character distances to the back.
0 or function key [Home] This is the number "0": Move to the front of the line prompt (common)
$ or Function key [end] moves to the last face of this line prompt (common)

H the first character of the line that the cursor moves to the top of the screen
M cursor moves to the first character of the Central line in this screen
L the first character of the line that the cursor moves to the bottom of the screen
G move to the last line of this file (common)
NG N is a number. Move to the nth row of this file. For example 20G moves to line 20th of this file (mates: Set Nu)
GG moved to the first line of this file, quite 1G Ah! Common
N<enter> N is a number. Move the cursor down n rows (common)

Search and replace

/word looks under the cursor for a string called Word. For example, in the file search Vbird This string, you can enter/vbird! Common
Word looks for a string above the cursor with a string name of Word.
NThis n is the English key. Represents "repeating the previous search". For example, if we just executed/vbird to search for Vbird this string,
When n is pressed, the next string that is named Vbird will continue to be searched downward. If the Vbird is executed, then pressing N will continue to search for the string named Vbird!

N This N is the English key. In contrast to N, the previous search for "reverse" is performed. For example/vbird, pressing N means "up" to search for Vbird.

: n1,n2s/word1/word2/g N1 and N2 are numbers. Look for the string word1 between N1 and N2, and replace the string with Word2!
For example, search for vbird between 100 and 200 rows and replace it with Vbird: ": 100,200s/vbird/vbird/g". Common

: 1, $s/word1/word2/gLook for the word1 string from the first line to the last line and replace the string with Word2! Common

: 1, $s/word1/word2/gc look for the word1 string from the first line to the last line, and replace the string with Word2! and display the prompt character before the substitution to confirm (confirm) if the user needs to be replaced! Common


Delete, copy, and paste

X, X In a line of words, X is the backward deletion of a character (quite a [del] key), X is to delete a character forward (rather [backspace] is the backspace) (commonly used)
Nx N is a number that continuously deletes n characters backwards. For example, I want to delete 10 characters in a row, "10x"
Dd Delete the entire column where the cursor is located (common)
Ndd N is a number. Delete the down n column where the cursor is located, for example, 20DD to delete 20 columns (common)
d1g Remove all data from the first row of the cursor
Dg Remove all data from the last row of the cursor
d$ Delete the last character of the row where the cursor is located
D0 That is 0 of the number, delete the cursor at the top of the line, and the first character
Yy The row where the cursor is copied (common)
Nyy N is a number. Copy the down n column where the cursor is located, for example, 20yy to copy 20 columns (common)
y1g Copy all data from the column to the first column of the cursor
YG Copy all data from the column of the cursor to the last column
Y0 Copy all data from the same character as the cursor to the beginning of the line
y$ Copy all data at the end of the line with the same character as the cursor
P, p p to paste the copied data on the next line of the cursor, and p for a row on the cursor!
J Combine data from the cursor column and the next column into the same column
C Repeatedly deleting multiple data, such as deleting 10 rows down, [10CJ]
U Restores the previous action. Common
[Ctrl]+r Redo the last action. Common
. Don't doubt it! This is the decimal point! means to repeat the meaning of the previous action. If you want to repeat the deletion, repeat, and so on, press the decimal point "." It's all right! Common


Enter an INSERT or replace edit mode

I, I I is "inserting from the current cursor," and I is "inserting at the first non-whitespace space at the current line." Common
A, a A is "insert from the next character where the cursor is currently located" and A is "start at the last character of the line where the cursor is located." Common
O, O This is the case of the English letter O. o Insert a new line at the next line where the cursor is currently located; O insert a new line on the previous line where the cursor is currently located! Common
R, R R will only interest the character of the cursor at a time; R will always be interested in substituting the text of the cursor until ESC is pressed; (common)


Instructions for storing, leaving, etc. of the instruction column

: W Write the edited data to the hard drive archive (common)
: w! If the file property is read-only, the archive is forced to be written. However, in the end can be written, or with you on the file permissions related Ah!
: Q Leave VI (Common)
: q! If you have modified the file, do not want to store, use! Do not store files for forced departures.
: Wq To leave after storage, if: wq! After forcing the store to leave (common)
Zz This is a capital Z Oh! If the file has not changed, then do not store away, if the file has been altered, then store and leave!
: w [filename] Save edited data to another file (similar to save new file)
: R [FileName] In the edited data, read the data from another file. The file "filename" will be added to the cursor row after the
: n1,n2 w [filename]Store the contents of N1 to N2 into the filename file.

:! Command temporarily leaves VI to command column mode to perform command display results! For example ":! Ls/home "You can see in VI the file information under/home with LS output!


Key meanings of block selection

V Character selection, the cursor will pass through the local anti-white selection!
V Row selection, the line that the cursor passes through is reversed!
[Ctrl]+v Block selection, you can select the data in a rectangular way
Y Copy the anti-white place.
D Remove the anti-white place

keys for multi-file editing

vim/host1.conf/host2.conf Editing Multiple Files
: N Edit Next file
: N Edit Previous file
: Files List all the files that are currently open for this vim

key functions in multi-window cases

: SP [filename]Open a new window, if there is a filename, to open a new file in a new window, otherwise two windows are the same file content (synchronized display).
[Ctrl]+w+ J Press the button by pressing [Ctrl], then pressing W and then releasing all the keys, then pressing J (or DOWN arrow arrows), the cursor can be moved to the window below.

[Ctrl]+w+↓

[ctrl]+w+ K Ditto, but the cursor moves to the window above.
[Ctrl]+w+↑

[ctrl]+w+ Q is actually: Q End away! For example, if I want to end the window below, then use [ctrl]+w+↓ to move to the lower window, press: Q to leave, you can also press [ctrl]+w+q Ah!]

Vim's environment setting parameters

: Set nu Displays the line number, which, when set, displays the line number of the row in the prefix of each row
: Set Nonu instead, the line number is canceled!

: Set Hlsearch Hlsearch is the high-light search (higher brightness search). This is the setting of whether or not to searchOfstring anti-whiteOfSet the value. The default value is Hlsearch
: Set Nohlsearch

: Set AutoindentAuto indent? Autoindent is automatically indented.
: Set Noautoindent

: Set Backup Do you automatically store backup files? Generally nobackup, if you set backup, then when you change any of the files, the source file will be saved as a file named filename~.

: Set Ruler Remember some of the status bar descriptions we mentioned in the lower right corner? This ruler is showing or not showing the setting value!

: Set Showmode This is whether you want to show the--insert--and the like in the lower left corner of the status bar.

: Set backspace= (012)In general, if we press I into edit mode, you can use the BACKSPACE bar (BACKSPACE) to delete any character.
However, some distribution are not allowed to do so. At this point, we can set it through BACKSPACE, when BACKSPACE is 2.
, it is possible to delete any value; 0 Or 1 o'clock, only the characters you just entered can be deleted, but you can't delete text that already exists!


: Set all displays all currently set values for the environment parameter.
: Set Displays the setting parameters that are different from the system defaults, which is generally the setting parameter you have changed yourself!
: Syntax on does the program-related syntax show different colors? For example, when editing a plain text file, the line will turn blue if it starts with #. If you know how to write a process
: syntax off sequence, then this: syntax on will also take the initiative to help you remove the wrong! However, if you are only writing plain text files, to avoid the interference of color on your screen, you can cancel this setting

: Set Bg=dark can be used to display different color tones, and the preset is "light".
: Set Bg=light

A summary of the quick operation of Vim under Linux

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.