Ii. Introduction to the VIM editor

Source: Internet
Author: User

Vim (vimsual) is a universal full-screen editor in the Linux/unix series OS.

Vim is divided into two states, that is, the command state and the editing state, in the command state, the type of character system is processed as a command, such as: Q for Exit, and the editing state is used to edit the text data. When you enter vim, the command state is entered first. In the command state, press "I" (insert) or "a" (add) can enter the editing state, in the editing state, press Esc key to enter the command state.

In the command state, there are some common commands:


A add text from behind the cursor

A adds text starting at the end of the line where the cursor is located


I insert text starting at the front of the cursor

I insert text from the beginning of the line where the cursor is located

Delete and modify:

X Delete the character at the cursor

DD Delete the entire line where the cursor is located

3DD Delete the row of the cursor and the following two lines

D Delete the text of the cursor to the end of the line, common terms Delete Comment statement (d$)

Cursor Movement:

In remote login mode,vim does not support PageUp,PageDown,Home, End and other function keys! ( depressed bar )

^ cursor moves to the beginning of the line

$ cursor moves to end of line

Ctrl+d down Half page

Ctrl+f down one page

Ctrl+u up half a page

Ctrl+b up one page

GG cursor navigates to document header

G cursor navigates to end of document

H cursor is positioned to the top of the current page

L cursor navigates to the beginning of the last line of the current page

W cursor moves backward one word

b cursor move forward one word

[n]+ cursor moves backward n rows , [n] represents an integer

[n]-cursor moves forward n rows , [n] represents an integer

N The G cursor is positioned at the beginning of the nth line and [n] represents an integer

Find and Replace:

/[STR] Find string str,[str] indicates the string to find

A carriage return highlights all found strings and then

Command n moves to the next found string, and the command n moves to

The last string found Eg/hello

Partial substitution ( can only replace the row where the cursor is located )

: S/[SRC]/[DST]/I ignore case /g all match eg:s/hello/world/ig Replace line

: 3,6 s/[src]/[dst]/ig(3-6 line) eg:3,6 S/hello/world

Replace All

:%s/[src]/[dst]/g replaces all src strings in the document with the DST string

:%s/^//g The space at the beginning of each line of the document

Block Operation:

V Visualize block selection state, after the block is selected, the block can be deleted (d), copied (y), cut (x)

yy the entire line where the cursor is copied

[N]yy copies n rows from the beginning of the cursor, [n] represents an integer

p Paste the copied text at the cursor

u undo Last Action


: Q exits without modifying the document

: q! Discard changes to the document and forcibly exit

: W Document to disk

:wq document to log out


: Help command to view the command's helpful tips

:%!xxd hex Mode

:%!xxd–r return text mode

If you accidentally press Ctrl+s,vim during editing, you will be in a zombie state and press ctrl+q to recover.

Perform vim +3 main.c// to locate line 3 of main.c

Perform vim +/printf main.c// to navigate to the first printf Place

Enter in command mode : New 2.c//to open a vim again , which is horizontal with vnew 2.c for portrait

VS 2.c//Portrait split.

You can also : Split Vsplit sp VSP, switch between two windows:ctrl+w,w

Enter gg=g in command mode to automatically align

SED: pipeline Lookup Replacement Program

Cat A.txt | Sed ' s/aa/bb/' > b.txt// replace aa in a.txt with BB and redirect output to B.txt the.

Ii. Introduction to 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.