A fantastic VIM editor tour

Source: Internet
Author: User

I. BACKGROUND

For the operation of the Linux server, we often use vim, and sometimes I use the vim is not so skilled and deep, this week in-depth study of the use of vim, including the introduction and advanced, first share to you, but also convenient to review the query.

Ii. introduction of VIM

1. Start vim using the command: Vim fileName

If the file exists, the content is opened and displayed, and if the file does not exist, a new file is created the first time it is saved.

Three modes of 2.vim

Command mode: You can move the cursor, delete, copy, search.

Insert mode: You can enter this mode to modify the contents of a file by entering any of the characters in "a", "I", "O".

Extended mode: Enter this mode by entering the ":" Character, you can exit, save, find and replace operations. (If you can press the ESC key in insert mode to return to command mode and do that).

3. Move the cursor in command mode

Use "H", "J", "K", "L" to move left, down, up, to the right, or use the arrow keys.

"W" moves to the next word, and "B" moves to the previous word.

4. Delete, modify, copy operation in command mode.

    

That

Line: CC (Modify), DD (delete), yy (copy)

Characters: Cl (Modify), DL (delete), yl (copy)

Word: CW (Modify), DW (delete), yw (copy)

5. Undo Action

"U", undo last modification Undo

"U", Undo all modifications

"Ctrl+r", cancel the last revocation, redo

6. Find operation (in extended mode or command mode)

"/keyword", search backwards

"? keyword", Search forward

"N" to find the next

"N" to find the previous

7. Paste

"P or P": Pastes copied, modified, or deleted data. (The data that is modified and deleted in command mode is copied to the Clipboard by default)

For row data, "P" is pasted to the previous line, and "P" is pasted to the next line.

For character data, "P" is pasted to the left of the character, "P" is pasted to the right of the character

8. Some tricks in command mode

"DTC", removing all characters from the cursor to the character C

"RC" to replace the characters under the cursor with the C character

"DW", removing all characters from the cursor to the end of the word where the cursor is located

"Ndd", delete the cursor to start the next n rows of data, such as 5DD.

"Nyy", copy the data from the beginning of the cursor down n rows, such as 3yy.

"NX", deleting n characters from the beginning of the cursor, such as 4x.

"R", enter the replacement state and press the ESC key to exit.

9. Exit, save, and enter the extended mode

Command mode and insert mode press ESC and enter ":" Into extended mode

": w", Save

": Q", exit

": Wq", Save and exit

": w!", forcing save

": q!", forced exit

": wq!", Force save exit

Third, the VIM editor uses the advanced

1. In-file positioning (Command mode)
"G" to jump to the last line of the file
"1G", jump to the first line of the file
"Ctrl+d", scroll down half screen
"Ctrl+u", scroll up half screen

2. Screen positioning related (Command mode)
"H", jump to the first line displayed on the screen
"M", jumps to the middle line displayed on this screen
"L", jump to the last line displayed on this screen
"Z" + "Enter" to make the current line the first line of the screen display
"Z" + "-" to make the current line the last line of the screen

3. Find and Bulk replace (in extended mode)
Search by sed, ": s/keyword/replaceword/g"
Replace all keyword of the current line with Replaceword, and if you do not add "/g", only the first keywords
Find the current row by default
N1,N2, N1 to N2 line of the file, such as: 1,10 s/a/123/g replace the first to the tenth in a 123
1,$, looking for the entire file

4. Read and save (in extended mode)
": R FileName" reads the content of another file into the current file
"1,20 W File" writes the contents of the 1-20 rows of the currently edited file into a new document
"1,$ W File" writes the entire document to a new
"1,20 w >> file" Appends 1-20 lines of the current edit

5. Settings (in extended mode)
1. ": Set", Display common configuration options
2. ": Set All", display all configuration options
3. ": Set number", set line numbers

Iv. Summary

Through this study, we have the VIM editor to get started and advanced understanding, when we mastered these skills, the use of Vim under Linux to manipulate the text becomes no longer difficult, very cool there are wood ~, in order to dream, I have been on the road, you?

    

    

A fantastic VIM editor tour

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.