"Go" vim operation

Source: Internet
Author: User

Reprint Address: http://blog.51yip.com/linux/1140.html

When I was in touch with Linux, I used the nano text editor, and personally felt that his greatest advantage was convenience and speed. Open files, modify files, to exit are very fast and simple. This is better than Vi,vim, but the nano can not display color words, the whole row can not be deleted, editing various configuration files, the total feeling is not very convenient. For the nano of these shortcomings, vim can be a good solution, and vim open the file, the word is color, this point root editplus,eclipse is the same, for the program, it is more cool. The following operations are in the command state, do not enter the insertion state, if entered into the Insert State, [ESC] exit the input state

One, the cursor moves

We do not think that the cursor movement is not important, in fact, it is the foundation, better cursor movement, copy, paste, delete, etc. to be more handy, into the editor inside, the mouse can not be used.

Cursor movement
h or LEFT ARROW key (←)

20h or 20 (←)

The cursor moves one character to the left

The cursor moves 20 characters to the left,

J or DOWN ARROW key (↓)

20J or 20 (↓)

Move the cursor down one line

Move the cursor down 20 lines,

K or Up ARROW key (↑)

20k or 20 (↑)

Move the cursor up one line

The cursor moves up 20 lines,

L or right ARROW key (→)

20l or 20 (→)

The cursor moves one character to the right

The cursor moves 20 characters to the right,

One thing to note here is that you don't use the keypad to enter numbers, or you'll enter the pattern directly. Personally feel that mastering the above, basically can meet our requirements of the cursor movement, see

Vim

We can judge by the number in the lower right corner of the editor, which line we want to jump to, if we want to be more precise, set NU sets the environment variable, let it show the line number is the best

Ctrl + F Screen "Down" to move one page, equivalent to [PAGE DOWN] key (common)
Ctrl + b Screen "Up" to move one page, equivalent to [PAGE UP] key (common)
Ctrl + D Screen "Down" to move half a page
Ctrl + u Screen "Up" move half page
Ctrl + E Screen "Down" to move one line
Ctrl + y Screen "Up" to move one line
+ Cursor moves to the next column of non-whitespace
- Cursor moves to the previous column of non-whitespace
N<space> That n means "number", press the number and then press the SPACEBAR, and 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.
N<enter> N is a number. Move the cursor down n rows (common)
0 or function key [Home] This is the number "0": Move to the front of the line prompt (common)
$ or Function key [End] Move to the last face of this line prompt (commonly used), where the $ in the regular is the meaning of the end, so that understanding can remember
H The cursor moves to the first character of the line at the top of the screen, h you write it down as the abbreviation for the header, so it's okay to remember
M The cursor moves to the first character of the line in the central of the screen, and m you write it down as middle abbreviation.
L The cursor moves to the first character of the line at the bottom of the screen, l you write it down as the last abbreviation.
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 will move to line 20th of this file.
Gg Move to the first line of this file, equivalent to 1G Ah! Common

Second, delete, copy, paste, undo

Delete, copy, paste, undo
X, X In one line of words, X is the backward deletion of a character (equivalent to the [Del] key), and X is to delete a character (equivalent to [backspace], which is the backspace) (common)
Nx

Nx

N is a number that continuously deletes n characters backwards. For example, I want to continuously delete the 10 characters after the cursor, "10x".

N is a number that continuously deletes the n characters preceding the cursor. For example, I want to delete the 10 characters before the cursor, "10X".

Dd

Yy

Delete the entire line where the cursor is located (common),

Copy the line on which the cursor is located (common)

Ndd

Nyy

N is a number. Delete the row where the cursor is down n rows, for example 20DD to delete 20 rows (common)

N is a number. Copy cursor row down n rows, for example 20yy copy 20 rows (common)

d1g

y1g

Delete all data from the row to the first row of the cursor

Copy all data from the row to the first row of the cursor

Dg

YG

Delete all data from the row to the last row of the cursor

Copy all data from the row to the last row of the cursor

d$

y$

Delete the cursor to the last character of the line

Copy all data at the end of the line with the same character as the cursor

D0

Y0

That's 0 of the number, remove the cursor, and go to the front of the line.

Copy all data from the same character as the cursor to the beginning of the line

P, p P Paste the copied data to the next line of the cursor, p paste the copied data to the previous line of the cursor
J Combine data from one row of the cursor to the same line
C Repeatedly delete multiple data, you can use the up and down keys to decide to delete the cursor above, or the following
U Revoke. Common
Ctrl + R Revocation of withdrawal. Common

Three, block selection, find, replace

Block selection, find, replace
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

V or V

CTRL + V

As can be seen from the above, V and V are mainly carried out, row selection, and Ctrl + V is the choice of the column, in terms of flexibility, CTRL + V more flexible.
/string

? string

Look under the cursor for a name called string string

Look above the cursor for a name called string string

N

N

Forward lookup, the search for a string, can be understood as next

Reverse lookup, search out the string, can be understood as not next

Find

To illustrate, the difference between N and N, made an example, look at the left, the left is the result of searching ddd, the yellow black word is the result of the search, at this time, we can press N or N, in these 4 search chunks within, to switch.

The order of N is 12341234

The order of N is 43214321

In a word, n is from top to bottom, n is from bottom to top

: n1,n2s/string1/string2/g The N1 here is the number of start rows to find, and N2 is the number of rows to find the end. ": 2,7s/ddd/fff/g" in line 2nd, line 7th, replace DDD with FFF
: 1, $s/string1/string2/g Look for the string1 string from the first line to the last line, and replace the string with string2! Common
: 1, $s/string1/string2/gc Look for the string1 string from the first line to the last line, and replace the string with string2! and display the prompt character before the substitution to the user to confirm (confirm) whether need to replace! Common

Four, save, exit, environment variables

Save, exit, environment variables
: W

: w!

Write the edited data to the hard drive archive (common)

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

: q!

Leave VI (Common)

If you have modified the file, do not want to store, use! Do not store files for forced departures.

: Wq

: wq!

Left after storage

Forced to leave after storage

Zz This is the capital Z! If the file does not change, then do not store away, if the file has been changed, then save and leave!
: w [filename] Save As
: R [FileName] In the edited data, read the data from another file. The file "filename" is also added to the following line of the cursor
:! Command Temporarily leave VI to command column mode to perform command display results! For example ":! Cat./test "To view the contents of the test file in the current folder in VI
I,i,a,a,o,o,r,r Into the insert mode, although there are differences, the feeling is not very different, put together
Esc Exit insert mode, enter command mode
: Set Nu It is useful to show the line number, after setting it, to display the row number of the row in the prefix of each row, which is much more convenient when we modify the configuration file to know how many rows.
: Set Nonu In contrast to set Nu, cancels the line number

Five, summary

Personally feel that the above operation can meet, 80%--90% of the needs of people, if the operation of multiple files, I think a variety of development tools, more convenient than vim.

One



"Go" vim operation

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.