Vim, minimalist tutorial, lets you instantly escape the pain of a mouse switch

Source: Internet
Author: User

Before writing, the mind can most commonly used to familiar with the operation of Vim, the content is not much, write half do not find, even the most commonly used operation, finish to write a lot, already can not be called a minimalist tutorial, but since the writing, so it

All say vim is difficult to learn, yes, relative to the mouse, it must be super difficult to learn. But it's really a lot of benefits, especially for the students knocking on the code. On these issues, today is not discussed, the main point here is that as long as the small part of the operation, you can easily use Vim, still can greatly improve the efficiency of knocking code OH.

Many of the online introduction of vim articles, all in the introduction of its powerful operation, in fact, increased the difficulty of learning, I simply summed up a bit, to use VIM only need to remember so few operations:

1. Operation mode

2. Move the cursor

3. Copy/paste

4. Delete

In fact, as long as the mastery of these points, proficiency, you can easily deal with. Of course, to adapt to the daily work of the code, but also to the directory and file operation familiar, as the second part of the content bar

1. Directory operation

2. File operation

Each item has a few operations, a little familiar with, it can be very good use, more than a moment, immediately will find, give up the pleasure of the mouse.

Operating mode

1, Mobile mode . This is the name I took, the document called Normal mode, not enough image, so I call it mobile mode, a listen to understand

ESC: Exit from other mode, enter mobile mode, preferably double-click

2, editing mode . The document is called insert mode, or editing is better. There are several ways to enter the editing mode, adapt to different scenes, are easy to operate, the keys are as follows:

I : Enter in front of the cursor's current position

a: Enter after the cursor's current position

SHIFT + I: Enter at the beginning of the line

Shfit + a: Enter at the end of the line

o: Enter a new line below the line where the cursor is located

SHIFT + O: Opens a new line above the line where the cursor is located

3, select the mode . Forget about what's on the document, but the choice is well understood. There are two types of selection modes:

v: Enter select text mode. The text will be selected from the current cursor position, moving the cursor. During this time, you can use the move cursor action to move.

Ctrl + V: for special operation mode. Also I take the name, originally called Block operation mode, what is block? Not understand. The most useful action is to add a uniform header or tail to multiple lines, such as: You can add an annotation at all the beginning of a selection, or you can add a semicolon at the end of all selected lines. You can also use the move to the beginning of the line or to the end of the operation.

Move

1. Moving between rows

J: Move Down one line

k: Move up one line

GG: Move to first line of document

SHIFT + G: Move to the last line of the document

shift + H: Moves to the first row of the current screen

SHIFT + M: Moves to the middle row of the current screen

SHIFT + L: Move to the end line of the current screen

: Line number : Moves to the row of the corresponding line number

Ctrl + D: Page Down

Ctrl + U: Page Up

Special instructions (do not say the good understanding, to say that not too understood):

Current screen : is the part that is displayed in Vim, the part not shown is not counted in, it inside the middle and lower position of the movement, that is, in the visible part of the.

: Line number : This operation can be divided into three parts:

1, SHIFT +: Enter the input mode.

2. Enter the line number.

3, enter.

The cursor jumps to the line where the line number is entered.

2. Move within the line (all lowercase letters)

h: Move left one

l: Move right One

W: Jumps to the beginning of the next word

e: Jumps to the ending of the current word

b: Jumps to the beginning of the current word, if the cursor itself is at the beginning of the current word, then jumps to the first word

Shfit + ^: Jump to the beginning of the line

SHIFT + $: Jump to end of line

F character : Jumps to the next position of the same character. Then press; you can continue to jump to the next position of the same character

shift + F character : Jumps to the previous position of the same character. Ditto, then press; you can continue to jump to the next position of the same character, except that the direction is the opposite.

Special Note:

F character : The operation is divided into two steps:

1. Press F

2. Press one character

This way the cursor jumps directly to the first occurrence of the corresponding pressed character after the current cursor (a good mess), for example:

My name is Onlyfu.

When marked on the first character M, press F First, then O, the cursor jumps to the O position. If you press n after F, the cursor jumps to the position of the first n that appears, that is, the name of N, which, if pressed, jumps to the second N, which is the N of Onlyfu, and can continue to the point, and if there is N, it will continue to jump over.

shift + F character : And F character is the same, just jump forward instead of jumping backwards, that is, a reverse direction operation.

Of course, there are some moving methods, the above operation is enough, here is not talk about.

Copy/paste

1. Copy a row

yy: The copy cursor is in the row

2, duplicate multiple lines

YJ: Copies the current line of the cursor and its next row, in a total of two rows

YK: Copies the current line of the cursor and its previous row, a total of two rows

y: Line number : Copy fishing village The current row to the corresponding line number includes the corresponding line number row, a total of multiple rows

In fact, more than YY, copying multiple lines can also be used to copy the selection of the operation to achieve

3. Copy Selected content

v Move cursor y: Copies the selected content. This is actually a three-step operation:

1, press the V key, enter the selection mode

2, move the cursor, using the method of movement to move, between the lines, the operation of the line is possible

3. Press the Y key to copy all the selections and enter the mobile mode

4. Paste

P: Paste the copied content out. There are two cases of pasting:

1, if the entire row of the copy, paste will be in the current cursor line of the next line pasted out, this will be the previous line in the order of all the following move down

2, if the copy is not an entire line, just inline or inline characters, paste will be inserted in the pre-makeup cursor position directly into the copied content, will not create a new row.

These two points to pay special attention, or copy and paste will not be as you wish

Delete

Delete and copy are the same

1. Delete a row

DD: Delete cursor in the row

2. Delete multiple lines

DJ: Delete the line of the cursor and its next row, a total of two lines

DK: Delete the line of the cursor and its previous row, a total of two rows

D: line number D: Delete the line between the cursor and the corresponding line number, including the corresponding line number of all lines, a total of multiple lines

Note that the delete operation will copy the deleted content at the same time, so that you can move the row, for example, if you want to move the 3rd line to line 5th, delete the 3rd line first, and press paste on the 4th line.

Well, the above is the simplest explanation, also wrote so much, the following directory and file operation put the next time to speak. Vim is a bit more difficult to get started, just calm down and press the operation for a moment, I believe, you will love it.

Vim, minimalist tutorial, lets you instantly escape the pain of a mouse switch

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.