Run the following Vim command to switch to Linux.

Source: Internet
Author: User

 

1. Outside of the insert mode

Basically, you should stay in the insert mode as little as possible, because in the insert mode, VIM is like a "dumb" editor. Many new users will stay in the insert mode because it is easy to use. But Vim is powerful in its command line mode! You will find that after you get to know Vim more and more, you will spend less and less time using the insert mode.

2. Use H, J, K, and l

The first step to use Vim for efficient editing is to discard the arrow keys. With vim, you do not need to move between the arrow keys and the keys frequently, which saves you a lot of time. In command mode, you can use H, J, K, and l to implement the left, bottom, top, and right arrows respectively. You may need to adapt to this method at the beginning, but once you get used to this method, you will find the efficiency of this operation.

When you edit your email or other text with paragraphs, you may find that the direction keys are different from what you expected. Sometimes you may skip many lines at a time. This is because your paragraph is a long line in Vim's view. In this case, you can type a G before H, J, K, or l, so that Vim will move as you wish on the screen.

3. move the cursor effectively in the current row

Many editors only provide simple commands to control the movement of the cursor (such as left, top, right, bottom, to the beginning/End of the line ). Vim provides many powerful commands to satisfy your desire to control the cursor. When the cursor moves from one point to another, the text between the two points (including the two points) is called "Crossing", and the command here is also called "motion. (This important concept will be used later)

4. Commonly Used commands (motion)

FX: move the cursor to the next X of the current row. Obviously, X can be any letter, and you can use; to repeat your previous F command.

TX: similar to the preceding command, but it is moved to the left of X. (This is really useful)

FX: it is similar to Fx, but you can look back. To repeat the previous F command.

TX: similar to TX, but it moves back to the right of X.

W: move the cursor forward to a word.

B: Move a word behind the cursor.

0: move the cursor to the beginning of the current row.

^: Move the cursor to the first letter of the current row.

$: Move the cursor to the end of the row.

): Move the cursor to the next sentence.

(: Move the cursor to the previous sentence.

5. move the cursor effectively throughout the file

Vim has many commands that can be used to reach the desired place in the file. The following are some commands for moving data in a file:

<C-F>: Move a screen down.

<C-D>: Move the half screen down.

<C-B>: Move a screen up.

<C-U>: Move the half screen up.

G: to the end of the file

Numg: move the cursor to the specified row (Num ). (For example, 10 Gb is to 10th rows)

GG: to the beginning of the file

H: move the cursor to the screen

M: move the cursor to the center of the screen

L: move the cursor to the screen

*: Read the string at the cursor and move the cursor to where it appears again.

#: It is similar to the above, but it is looking in the opposite direction.

/Text: search for the string text from the current cursor and reach the place where the text appears. You must press enter to start the search command. If you want to repeat the previous search, press n to move to the next text, and then press n to move to the previous text.

? Text: similar to the above, but in the opposite direction.

M {A-z}: Mark a single letter named a-Z at the current cursor position. Only lowercase letters are allowed. You can't see the existence of bookmarks, but it is already there.

'A: To bookmarks. Note that this is not a single quotation mark. It is generally located on the left of 1 of most keyboards.

'.: The last time you edited the file. This command is useful, and you do not need to mark it yourself.

%: Moving between pairs of parentheses and other symbols, such as pairs. Place the cursor on any symbol, and then use % to move to the symbol that matches the symbol. % can also correctly identify the nested layers of the brackets and always move to the truly matched position. Therefore, this command is very useful when editing program code, so that you can easily move between the beginning and end of a piece of code.

Efficient input

1. Automatically complete with keywords

Vim has a very beautiful keyword auto-completion system. This means that you can enter a part of a long term, and then press a key. Then Vim completes the long term input for you. For example, you have a variable named iamalongandawkwardvarname. Maybe you don't want to input it one by one every time.

With the keyword AutoComplete function, you only need to enter the first few letters (such as iamal), then press <C-N> (press Ctrl, then press N) or <C-P>. If Vim does not give the words you want, continue to press until you are satisfied, VIM will keep repeating the matching strings it finds.

2. Enter the insert mode intelligently

Many new users only use I to enter the insert mode. In this way, you can enter the insert mode, but it is usually not that appropriate, because Vim provides many commands to enter the insert mode. Below are some of the most commonly used:

I: insert it to the left of the Current Character

I: insert at the beginning of the current row

A: insert it to the right of the Current Character

A: insert at the end of the current row

O: Insert a new row under the current row.

O: Insert a new row on the current row.

C {motion}: Delete the characters crossed by the motion command and enter the insert mode. For example: C $, this will delete the characters from the cursor position to the end of the line and enter the insert mode. CT !, This removes the exclamation point from the cursor position to the next one (but not included), and then enters the insert mode. The clipboard is deleted and can be pasted out.

D {motion}: similar to the above, but does not enter the insert mode.

3. valid text for moving large segments

Use Visual selections and the appropriate selection mode

Unlike the original VI, VIM allows you to highlight (select) some text and perform operations. Three Visual selection modes are available:

V: select by character. Frequently used mode, so try it yourself.

V: select by row. This is especially useful when you want to copy or move many lines of text.

<C-V>: select by block. Very powerful. This function is available only in a few editors. You can select a rectangle and the text in the rectangle is highlighted.

When selecting a mode, use the arrow keys and commands described above (motion ). For example, vwww highlights the three words in front of the cursor. Vjj will highlight the current line and the following two lines.

4. Cut and copy in visual selection mode

Once you highlight the selection area, you may want to perform some operations:

D: paste the selected content to the clipboard.

Y: copy the selected content to the clipboard.

C: paste the selected content to the clipboard and enter the insert mode.

Cut and copy in non-visual selection mode

If you know exactly what you want to copy or cut, you do not need to enter the visual selection mode. This will save time:

D {motion}: Cut the characters crossed by the motion command to the clipboard. For example, DW cut a word and DFS cut the character from the current cursor to the next S to the clipboard.

Y {motion}: similar to the above, but it is a copy.

C {motion}: similar to d {motion}, but enters the insert mode.

DD: Cut the current row.

YY: copy the current row.

Cc: Cut the current row and enter the insert mode.

D: cut from the cursor position to the end of the row to the clipboard.

Y: copy the current row.

C: similar to D, and finally enters the insert mode.

X: Cut the current character to the clipboard.

S: similar to X, but enters the insert mode at last.

5. Paste

Pasting is simple. Press p.

6. Use multiple clipboard

Many editors only provide one clipboard. There are many Vim instances. The clipboard is called a register in vim ). You can list all register names and their contents defined currently. The command is ": Reg ". It is best to use lower-case letters as the register name, because some of the upper-case letters are occupied by VIM.

The register command is double quotation marks.

For example, we want to copy the current row to register K. You should press "kyy. (You can also use v "Ky. Why ?) Now the current row should already exist in register K until you copy something into Register K. Now you can use the "kp" command to paste the content in register K to the desired position.

7. Avoid duplication

Amazing. Command

In VI, input. (decimal point) will repeat the previous command you entered. For example, if your last command is "DW" (delete a word), VI will delete another word.

8. Use numbers

Using numbers is also a powerful and time-saving feature of vim. You can use a number before many Vim commands. This number will tell Vim how many times this command needs to be executed. For example:

3j moves the cursor down three rows.

10 DD will delete 10 rows.

Y3t ″ will copy the content from the current cursor to the third quotation mark to the clipboard.

Numbers are very effective methods to extend the scope of the motion command.

 

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.