The basic usage of the VIM editor

Source: Internet
Author: User

Create/Open a text file


Vim filename (if the file does not exist, a temporary file is created in memory and will be transferred to the hard disk after saving)


Ii. Three modes of vim2.1 Command mode

The command mode is the default open mode.


2.1.1 Double-click the capital letter Z

Save and exit


2.1.2 Num + G

Jump to Num Line


2.1.3 G

Jump to the last line

2.1.4 Two lower case g consecutively

Jump to First line

2.1.5 (+n) yy

Copy Current row (n times)


2.1.6 P

Paste on the next line of the row where the cursor is located


2.1.7 (+n) DD

Cuts the current row (cuts n rows from the current line)


2.1.8 u

Revoke

2.1.9 Ctrl+r

Redo

2.1.10 x

Delete the character where the cursor is located


2.1.11 R

Replace the character where the cursor is located

2.1.12 R

Consecutive substitution of the character of the cursor


2.1.13 Ctrl + V

Select the area you want to copy up or down
Press the Y key to copy

2.2 Insert Mode

The shortcut keys for switching from command mode to insert mode are:


2.2.1 I

Inserts at the position of the current cursor


2.2.2 A

Inserts at the next position of the current cursor


2.2.3 O

Creates a new row on the next line of the current cursor and enters insert mode


2.2.4 I

Move the cursor to the beginning of the line and enter into insert mode


2.2.5 A

Move the cursor to the end of the bank and enter into insert mode


2.2.6 O

Creates a new row and enters insert mode on the previous line in the row where the cursor is currently located


2.2.7 ESC

Exit Insert mode and enter Command mode


2.3 Last-line mode

The shortcut keys for switching from command mode to last-line mode are:


2.3.1/

Enter a keyword to find
Press ' n ' when there are multiple find results to jump between results (top down), press ' n ' to jump from bottom to top

2.3.2:q

Exit


2.3.3:q!

Force exit


2.3.4:w

Save

2.3.5:w Path/filename

Save As

2.3.6:wq/x

Save and exit


2.3.7:set nu

Set line number (temporarily valid, to permanently take effect, modify the configuration file "VIM/HOME/FEIHU1996/.VIMRC", write ': Set Nu ' so that the line number will appear automatically each time it is opened)


2.3.8:set Nonu

Cancel line number

Replace operation


2.3.9:s/old/new/

Replace old with new (replace only the first keyword in the row where the cursor is located)


2.3.10:s/old/new/g

Replaces all the keywords on the line where the cursor is located

2.3.11:num1,num2s/old/new/g

Replaces all keywords from line num1 to line num2


2.3.12:., $s/old/new/g

Replaces all keywords from the current line to the last row


2.3.13:num1,.s/old/new/g or:., $s/old/new/g or:., $s -1/old/new/g

Replaces all keywords from the current line to the second-to-last line

2.3.14:1, $s/old/new/g

All keywords will be replaced (= = =%s/old/new/g)
If the keyword itself contains '/' in the Replace operation, it must be preceded by ' \ ' to escape
In a replacement operation, the delimiter '/' can also be substituted with other characters, such as ' # '
Replace operation, if the new keyword is empty, it will act as a delete

2.3.15:%s/^/#/g

At the beginning of each line, add "#"

2.3.16:%s/^#//g

Delete "#" at the beginning of each line


2.3.17:num

Position to Num Line


2.3.18:sp

Split screen


2.3.19:!+ external command

To execute an external command without exiting VIM


2.3.20:!! + External Command

Executes the external command without exiting vim and copies the results of the command execution into the current file



Press the ESC key continuously to exit the last line mode



This article comes from a personal website www.feihu1996.cn


This article is from the "feihu1996" blog, make sure to keep this source http://feihu1996.blog.51cto.com/12094951/1953367

The basic usage of the VIM editor

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.