Vim Editor Detailed

Source: Internet
Author: User

Vim is the enhanced version of VI, one of the important philosophical ideas of Linux is all files, and the majority of configuration files on the system are saved with a text file, so mastering a powerful, easy-to-use text editor for Linux system Management is very necessary.


Use of vim:

1. Open a file with vim

Vim [Options] File

If the file exists, Vim opens the file

If the file does not exist, VIM creates the file

Frequently used options for opening files using vim: +num +/pattern

The Vim +# file indicates that the cursor is positioned directly to the # line when it is opened

Vim + file indicates that the cursor is positioned directly to the last line when the file is opened

Vim +/pattern file indicates that the cursor is positioned to the first row that is matched to the pattern when the file is opened

Vim is a modal editor:

2.vim mode : Edit mode (Command mode)

Input mode

Last-line mode

Replacement mode//

Visualization Mode//

Edit mode: Also become the command mode, in this mode from the input of the keyboard is vim parsed into a command, and not as a character input

Input mode: In this mode, it is normal to write

Last-line mode: Similar to command mode, but more powerful

3.vim Mode Conversion

Use VIM to open a file by default into command mode

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/77/08/wKiom1ZhQ3fjUNhVAAB9Lr--Wuw186.png "title=" i{jp% nu% ' C_76nbwkx%u7[h.png "alt=" Wkiom1zhq3fjunhvaab9lr--wuw186.png "/>

Both the input mode and the last line mode must be entered from the command mode

Command mode into input mode: I,a,o,i,a,o

I: the character before the current cursor is transferred, and the character entered precedes the current cursor character.

A: The character after the current cursor is transferred, the character entered after the current cursor character

O: Create a new line below the current cursor line

I: At the beginning of the line where the cursor is currently located

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

O: Create a new line above the current cursor line and transfer to

Input mode back to command mode: ESC key

The command mode is transferred to the last line mode:

: Enter a colon into the last line mode

Last-line mode return command mode: ESC key


Simple commands commonly used in the last-line mode:

: Set Nu adds line number at the beginning of each line

: #d Delete Line #

: #1, #2d delete lines from # # to # line (. Represents the current row, $ represents the last row, + #表示从当前行向下的 # lines)

: s/pattern/string/g the global substitution to which the pattern is matched

:! command to execute the Bash command without exiting vim

4. Cursor movement (common, difficult)

(1) Move by character: H,j,k,l

Can be preceded by the # number, indicating one time to: Move a # character

(2) Moving words by word

[#]w: Move to the beginning of the next word

E: Move to the ending of the current word or the ending of the next word (end)

B: Move to the beginning of the first word or the first word of the current word (BEGIN)

Precede these commands with # to indicate one time to: Move # a Word

(3) in-line jump

0 (number 0): Quickly jumps to the beginning of the current line (absolute beginning)

^: Moves the cursor to the first character of the current line match either (relative to the beginning of a row)

$: Moves the cursor to the end of the current line

(4) Jump between rows

#G: Jump directly to Line #

G: Jump to the last line

In the last line mode: # jump to # # line

: $ jump to last line

5. Flip Screen

CTRL+F: Flip one screen down

Ctrl+b: Turn up one screen


Ctrl+d: Turn down half screen//associative memory: down

Ctrl+u: Turn up half screen//up


6. Delete (difficulty)

Delete a single character

X: Delete the character where the cursor is located

#x: Remove the # characters altogether from the character where the cursor is located

d command

D Delete command can be used in conjunction with the jump command

D W: Represents the deletion of the contents of the current cursor to the beginning of the next word

D 3e: Removes the position from the current cursor to the point where the cursor will jump

#d 3e: Remove the # range of a jump character's specified range

DD: means delete when forward

#dd: Represents the deletion from the current line starting at the total # line


7. Replication (common, difficult)

Y command

Usage with d command

YY for replication when moving forward

Need to be used in conjunction with jump commands to achieve replication flexibility

8. Paste

When you perform a paste operation, the pasted content is the most recent deletion or the most recent copy of the content.

P Command and P command

P: If the last time you copied or deleted an entire line of content, paste it below the line where the cursor is located

is not an entire line, it is pasted at the end of the character where the cursor is located

P: If the last time you copied or deleted an entire line of content, paste it above the line where the cursor is located

is not an entire line, it is pasted in front of the character where the cursor is located

9. Replace

R: A common term replaces a single character, that is, the character of the cursor

R: Transition from command mode to replacement mode

You can replace multiple characters with the cursor's movement

10. Visualization Mode

Enter the visual mode, you can break the limitations of the jump command in vim, with the mouse in Windows drop down, with the selected content to do the appropriate action

V and V commands

Both V and V can be transferred from the command mode to the visual mode

V: After moving into visual mode, selection of overlay content is selected by character

V: After moving into the visualization mode, the selection of the overlay content is selected based on the row


11. Undo the edit Operation

U command

U command to undo the previous edit operation

You can use the U command consecutively to undo the N edit operation

#u: Explicitly specify how many operations to undo

How to undo this action:

Ctrl+r: Undo the last Undo operation


12. Repeat the previous Operation

. You can repeat the previous operation


13: Find (Common)

In command mode (also available in last-line mode)

/pattern Search from the current cursor line to the tail

? PATTERN searches from the current cursor line to the header

N and N are used to jump between matching patterns (highlighting)

N: Jumps down, that is, jumps to the next pattern match position

N: Jump on the bottom, jump to the previous pattern match position

This is useful for locating fast parameters in a variety of service profiles.


14. Find and replace (common)

VIM supports SED in last-line mode

: addr1,addr2s/pattern/string/g

g = Global Substitution

In some cases, this function is more commonly used


When using vim to edit a file or write a script, jump, copy, paste, delete, etc. are more commonly used functions, which copy, paste, etc. are set up to jump, so flexible use needs constant practice


Commands that can be used in command mode can be used in the last-line mode, and the last-line mode can achieve more functions than in command mode.


15. Exit the VIM editor

Command mode: ZZ means save exit

Last-line mode: W means save

Wq Save exit


16. Use Vim to edit multiple files

When you open multiple files with vim

Vim File1 file2

When vim edits different files, copy, paste content can be shared, but cannot be shared with externally copied content, it is easy to understand, that is, VIM will copy the content in its own process address space

When Vim opens multiple files, because Vim is a full-screen editor, only the first file content will be displayed.

So, when editing multiple files at the same time, the common operation is to switch between these files

Last-line mode: Next uses the next command in the last-line mode to switch to the next file

: prev This command to switch to the first file

: Last this command can switch to the final file

: First this command can switch to file one

: Q Exits the current file

: QA quits editing of all files

This article is from the "Zxcvbnm Xuan ye" blog, please be sure to keep this source http://10764546.blog.51cto.com/10754546/1719683

Vim Editor Detailed

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.