How to use the vim editor

Source: Internet
Author: User
Use the VIM editor (case sensitive) and enter the VIM directory under the command line. open VIM, press I to enter edit mode, edit the text, and press esc to enter command mode. Preliminary Use: open VIM in the graphic interface, press I to enter the editing mode, edit the text, press esc to enter the command mode, and press: wq to save and exit,

Use of the VIM editor (case sensitive)

Enter the VIM directory under the command line, open VIM, press I to enter the edit mode, start to edit the text, and press esc to enter the command mode.

Preliminary use:

Open VIM in the graphic interface, press I to enter the editing mode, edit the text, press esc to enter the command mode, and press: wq to save and exit. Note that the command has a colon.

Continue to use:

There are three Vim modes: General mode, edit mode, and command line switch mode.

(1) keys in normal mode:

H move to left

J move down

K move up

L move to the right

CTRL f move one page down

CTRLb move one page up

CTRL d move down half page

CTRL u move up half page

+ Move the cursor to the next line without spaces

-Move the cursor to the previous line without spaces

N N indicates the number, plus space, and the number of characters to be moved to the current position.

0 Move to the beginning of the line change

H: The first character to move to the uplink,

The first character that M moves to the middle line.

L The first character in the row at the bottom of the screen.

G move to the last row of the file (frequently used)

NG row to the object

Gg moves to the first line of the file.

N Move the cursor to the first line of the file

/Word: specifies the WOED character of the search file. Down

? Word to search for a WORD character.

N this button is an English button, indicating that the previous search action is repeated,

N this button is an English button, indicating that the previous search action is repeated in the opposite direction.

: N1, n2s/word1/word2/g indicates that word1 of the n1-n2 row is replaced with word2

: N1, $ s/word1/word2/g is replaced with word2 from the n1-last row

: The functions of n1, $ s/word1/word2/gc are replaced with those confirmed above.

X deletes a character behind the cursor. Equivalent to DEL key

Nx n indicates that n characters are deleted.

Dd deletes the row where the cursor is located.

Ndd deletes n rows under the row where the cursor is located

D1G deletes all data from the row where the cursor is located to the first row.

DG deletes all data from the row where the cursor is located to the last row.

D $ delete all data from the cursor to the row.

D0 deletes all data from the row where the cursor is located to the first row

C. delete multiple data records repeatedly,

Yy copies all data in the row where the cursor is located

Nyy copies the n rows down where the cursor is located, and n is a number.

Y1G copies all data from the row where the cursor is located to the first row.

YG copies the data searched from the row where the cursor is located to the last row.

Y0 copies all data from the cursor to the first row.

Y $ copies all data from the cursor to the last row.

P paste the copied data to the following row

P paste the copied data up

J combines the row where the cursor is located with the next row into a row.

U restores the previous operation.

Ctrl + r repeat the preceding operation.

(1): Editing mode:

Common commands used to enter the editing mode.

I insert from the current cursor.

I. Insert the cursor from the first non-space position.

A. Insert the cursor from the next character.

A inserts the last character card from the row where the cursor is located

O insert a new row from the next row where the current cursor is located.

O inserts a new row into the previous row where the current cursor is located.

R enters a replacement insert, that is, insert a new row in the next row of the current cursor.

R always replace and insert until you press esc.

(2): command mode

: Wq saves the text and exits. if the file name is not specified, you need to: wq file name,

: W write

: Wq! Force write.

: Set nu display row number

: Set nonu cancel row number

: N1, n2 w Save the content of n1 and n2 to the filename File.

: R Read the contents of the filename file to the end of the current row where the cursor is located.

:! The Commad command is a command to exit temporarily and enter the command mode.

Notes for Using VIM

If you are using vim for editing, vim will create a file named filename under the edited file. swp file. when VIM is not normal when editing is in progress, a warning message is displayed when you open the edited file again, where O is read-only, e. open normally. R. load the cache file to open it. D. delete the cache file Q. leave vim. A. ignore the editing behavior,

Vim functions

Currently, distributions replace vi with vim. Enter alias in the terminal to find alias vi = 'vim '. if not, set it by yourself,

Block selection

Press V to make the row where the cursor is located perform the white turning operation, ctrl + v to perform the white turning operation on the block, and y or d to perform the white turning operation, you can copy the entire row.

: N: Edit the next file,

: N: Edit the previous file.

: Files: list all opened files of this vime.

Vim's multi-window function

If the file is large and CTRL + F or CTR + M is difficult to read the file, you can cut a file into multiple windows. the command is: sp + filename: if it is only sp, it only splits the current file. if it is sp + filename, it splits multiple files and moves between multiple windows, CTRL + W + j move down, ctrl + w + k move up, ctrl + w + q leave the current window.

The first time I used windows's edit, the edit feature was very powerful. now I find vim is even more powerful ....

Vim environment configuration

: Set nu

: Set nonu cancel row number

: Set hlsearch to set highlighted search

: Set nohlsearch cancel highlighted search

: Set backup

: Setruler description of the status bar

: Set showmode: whether to display the status bar in the lower left corner

: Setall: display all currently set environment parameters

: Set display parameters different from the system default value

: Whether syntax on displays different colors based on the related syntax of the program.

: Whether syntaxoff is an idiom-related syntax that displays different colors

: Set bg = dark display different color tones

: Set bg = light display different color tones

: Set autoindent Auto Indent

If you want to set these settings by default, you need to modify them in/etc/vimrc. However, it is recommended that you do not modify the file in bytes ~ /. Vimrc, which does not exist by default and is created by yourself,

The source is laruence's private dish.

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.