Vim Usage Summary

Source: Internet
Author: User

Vim is an upgraded version of VI and is an important text editor in Linux. The key features of VIM are:

1. Full Screen

2, support the mode switch

3, the function is exceptionally powerful.


The most common modes in VIM are the edit mode, the insert mode, and the last line mode. When Vim opens the file, the default is edit mode, sometimes called the command mode.

Ways to edit mode------> Insert modes are:

I: Insert the word match either the current cursor

A: specifier insertion at the current cursor position

o: Insert a new row below the current cursor line


I: Inserted at the beginning of the line where the current cursor is located

A: At the end of the line where the current cursor is inserted

O: Inserts a new row above the line where the current cursor is located.


Insert mode-----> Edit mode

Esc

Edit mode-----> last-line mode

Last-line mode------> Edit mode

Esc


Vim is a common operation.

First, open the file

1.1 Vim file, open if file exists, if it does not exist, open after creation

1.2 Vim +n file opens file and cursor navigates directly to Nth row

1.3 Vim + file opens file and the cursor navigates directly to the end of the line

1.4 Vim/patter file opens file and the cursor navigates to the position of the first match to pattern

1.5 vim FILE1 File2...vim can open multiple files at the same time. It is important to note that:

: Next Next file

: Pre Previous file

: Last File

: First File

Second, close the file (last line mode)

2.1:q exit does not save

2.2:w Save does not exit

2.3:wq Save exit

2.4:q! Force exit

2.5:wq! Forces the save to exit. Some files may be read-only, and administrators can force the save to exit

2.6:add1,add2w/pathe/to/file, save the contents of Add1 to ADD2 as FILE

2.7:zz, in edit mode, exit.

Third, mobile

3.1: Move between characters

H: Move left

J: Move Down

K: Move Up

L: Move Right

Support: #h, #j, #k, #l操作

3.2: Move between words

W: Moves to the ending of the word in the cursor or to the beginning of the next word

B: Move to the beginning of the word or the first word in the word where the cursor is located

E: Moves to the ending of the word in the cursor or to the first word of the next word

Support #w, #b, #e的操作

3.3: In-line jump

0: Jump to the absolute beginning

^: jumps to the beginning of a relative line, or the first non-null character in the row of the cursor

$: Jump to absolute end of line

3.4: Inline Jump

G: Jump directly to the last line

#G: Jump To Line #

Iv. Delete operation

4.1 x, delete characters by character. #x表示删除光标及以后的 # Characters

4.2 d Command

Support: D[w|b|e], #d [d|b|e],d[0|^|$]

4.3 dd command

DD Delete When moving forward

#dd Delete the current line and the # line below it

4.4 Delete in the last row mode

: 3,4d Delete line three to line fourth

:., +5d delete the line with the cursor and the 5 lines after it

:., $d Delete the line of light and the last

: 100,$-5d, delete the contents of row 100 to the bottom line fifth

4.5 Note that after multiple deletions, the last deletion can be used to paste.


V. Copy operation

5.1 y command

Support y[0|^|$]; support Y[b|w|e], that is, the Y command supports the use of inline jump commands and word-by-phrase move commands

5.2 yy Command

YY copy when moving forward

#yy复制当前光标及其下的 # Line

Six, paste operation

6.1p lowercase p If you copy or cut the entire line, paste it below the line where the cursor is located, and paste it to the rear of the cursor

6.2P uppercase P If you copy or cut an entire line, paste it above the line of the cursor and paste it in front of the cursor

Seven, turn screen operation

If you are opening a file with a large number of rows,

Ctrl+f: Next screen

Ctrl+b: Previous screen

Ctrl+u: Upper Half screen

Ctrl+d: Lower half screen

Viii. Revocation of operations

U command to undo the previous operation

#u可以撤销前 # Operations

Ctrl+r can undo the current undo operation

Nine, modify the operation

The C command, double-clicking two times C, deletes the current line and goes into insert mode.

X. The interaction between VIM and the shell

In the last line mode:! command to execute bash commands.

Xi. lookup (in the last line mode)

/pattern finds all items that can match/pattern from the cursor to the last line

? PATTERN finds all items that can match/pattern from the cursor to the first row

N Next

N Previous

12, find and replace (in the last line mode)

[Email Protected]@[email protected]

Where I means ignoring case

g = Global Substitution

13. Visualization (edit mode)

V: Can be selected by row

V: Can be selected vertically

14, repeat the last operation

.

Split Screen Display document

Ctrl+w,s Horizontal Split screen displays a file

Ctrl+w,v Vertical Split screen displays a file

CTRL+W, toggle cursor on screen key


16. Replace operation

R: replace one character

R: Direct transfer to replacement mode

17. Advanced topic: (All in the last line mode)

17.1:set Nu Set line number, set Nonu cancel line number

17.2:set AI set indent set noai Cancel indent

17.3:set IC Ignoring case set Noic canceling ignoring case

17.4:set Hlsearch set Find highlight set Nohlsearch cancel find highlighting

17.5:syntax on syntax highlighting syntax off canceling syntax highlighting

18. Vim Configuration file

/ETC/VIMRC Global VIM configuration file, valid for all users

~/.VIMRC is valid for the current user's vim configuration

If two files do not exist, you can create them yourself

19. file.swap Files and Vimtutor

If you use Vim to edit a file, an illegal exit will generate a. file.swap hidden file in the same directory of file, prompting each time you open it.

Vimtutor is a vim tutorial. You can refer to learning.

In Linux, the importance of vim is self-evident. Summary is only the first step, remember and can be used flexibly is the purpose. Try it.

Vim Usage Summary

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.