[Linux] Shortcuts for Vi and Vim editors

Introduction: [Linux Practical Part 1] Shortcut key exercises for Vi and Vim editors (must be content)

I. [Linux] Shortcuts for Vi and Vim editors-- Introduction


Hello, friends, the last column explained why in the Linux world, everything is a file?

The basic chapter has turned the page, let's open the practical chapter! This article mainly explains the basic use of the Vim editor, and it is also the most frequently used command. The blogger is slowly updating the learning of the Linux column. If you feel that the blogger's writing is not bad, you can pay attention to the column and learn together~~

2. [Linux] Shortcuts for Vi and Vim editors -- Basic introduction


Linux system will have built-in Vi text editor
Vim has the ability of program editing, which can be regarded as an enhanced version of Vi. It can actively identify the correctness of syntax by font color, which is convenient for program design and is widely used by programmers.
Since Vim is an enhanced version of Vi, the articles are explained in the Vim editor

3. [Linux] Shortcuts for Vi and Vim editors -- Common mode


1. Normal mode
Opening a document with Vim enters normal mode, which is also the default mode. In this mode, we can use the [Up, Down, Left, Right] keys to move the cursor; [Delete Character] or [Delete Entire Line] to process the file content; or [Copy] [Paste] to process the file data

2. Edit mode
Press any letter i , I, o, O, a, A, r, R to enter the edit mode

3. Command line mode
Enter ESC and then enter: In this mode, you can provide you with relevant commands to complete actions such as reading, saving, replacing, leaving Vim, and displaying line numbers.

Note: These three modes must be carefully learned and understood, and what mode should be entered to use what function!

4. Mode switching diagram

I really don't want to draw, so I just took a screenshot 😊

5. Common commands
Copy the current line yy , copy the 5 lines 5yy down from the current line, and paste (input p)
Delete the current line dd, delete the current line down 5 lines 5dd
Find a word in the file [command line/keyword, press Enter to find, enter n to find the next]
Set the line number of the file, cancel the line number of the file [under the command line: set nu and: set nonu ]
Edit letc /profile file, in normal mode, use shortcut keys to the last line [G] and the first line [gg] of the document
Type "hello" in a file, in normal mode, then undo the action u
Edit the letc /profile file, in normal mode, and move the cursor to, enter 20, and then enter shift+g
6. Practical exercises
Well, the nonsense before, then let's go to the actual operation

create a file
[ root@cabbage ~]# vim Hello.java

Then press i to enter edit mode and enter what you want:

Set line number, cancel line number

save and exit

: wq

Copy the number of lines, move the cursor to the line you want to assign, then click yy , and then press p. Note that it must be in the general mode, if you want to assign 3 lines, 3yy and then p is fine

Find a word in the file, note that it is on the command line, if you look for Cabbage
Summarize
It is very convenient to use Vim proficiently. When you first start learning, you must distinguish the use of three modes. Practice slowly, practice makes perfect!

Copyright statement: The content of this article is contributed by Alibaba Cloud's real-name registered users. The copyright belongs to the original author. The Alibaba Cloud developer community does not own the copyright and does not assume the corresponding legal responsibility. For specific rules, please refer to the " Alibaba Cloud Developer Community User Service Agreement " and " Alibaba Cloud Developer Community Intellectual Property Protection Guidelines ". If you find any content suspected of plagiarism in this community, fill out the infringement complaint form to report it. Once verified, this community will delete the allegedly infringing content immediately.

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00