Vim command Summary: vim command

Source: Internet
Author: User

Vim command Summary: vim command

I recently started to use Linux. Now I want to summarize the vim command from a beginner's perspective.

Four Vim Modes

1. Start Vim

 

1. Double-click the desktop icon to start Vim (GUI)

2. In the Start Menu, click Run and enter vim or gvim to start Vim or Gvim.

3. Enter the following command in the command line window:

Vim directly starts vim

Vim filename open vim and create a file named filename

Ii. Vim Mode 1. Common Vim mode:

Command-mode)

Insert-mode)

Visual mode)

Normal mode)

2. How to enter these modes ①. Normal Mode

The normal mode is mainly used to browse and modify text content.

Generally, the normal mode is used to open Vim. In any mode, you only need to press Esc to return to normal mode. The conversion of the following modes is first converted to the normal mode.

②. Insert mode

The insert mode is used to add content to the text, that is, to edit the text content.

Normal Mode ==> insert mode

Press I to start entering text before the character where the cursor is located and enter the insert mode

Press a to enter the text and enter the insert mode after the character where the cursor is located

Press o to open a new line under the row where the cursor is located to enter the text and enter the insert mode.

Delete the character of the cursor by s and enter the insert mode

Press I to enter the text at the beginning of the row and enter the insert mode. This line indicates the first non-blank character. If there is a space at the beginning of the line, enter the text after the space and enter the insert mode.

Press A to enter the text at the end of the row and enter the insert mode. This is easy to use. You don't have to worry about where the cursor is in this line. If you press A, you will be waiting for you to enter text at the end of the line.

Press O (uppercase letter O) to open a new line on the line where the cursor is located to enter the text and enter the insert mode.

Delete the row where the cursor is located by S and enter insert mode

 

③ Visual mode

The visual mode is equivalent to the normal mode after the highlighted text is selected.

The visible mode has a sub-mode. It selects the visible row mode based on the behavior unit and uses the "V" key to enter (that is, Shift + v ); and block-Based Visual block mode. Press Ctrl + v to enter.

Normal Mode ==> visual mode
By v visual mode
By V visual Block Mode

④ Command mode

Command mode is mostly used to operate text files (rather than the content of text files), such as saving files, or changing the editor status, such as setting multi-column windows, labels, or exiting the editor ......

Normal Mode ==> command mode
Press: (shift + semicolon)

 

Vim commands

In insert mode, keyboard operations are all about editing text content. The following commands are used in normal mode (commands starting with: Enter command mode first, in command mode, enter the following content)

Move command

H shifts one character to the left

L shifts one character to the right. This command is rarely used and is generally replaced by w.

(Commands h and l can only be moved in the current line, but cannot be wrapped in line)

K move one character up

J. Move one character down

The preceding four commands can be used with numbers. For example, 20 J means moving 20 lines down and 5 characters to the left for 5 hours. In Vim, many commands can be used with numbers, for example, to delete 10 characters of 10 characters

Insert 3 !, 3a! <Esc>, the Esc here is required, otherwise the command does not take effect.

W moves a word to the right (cursor stops at the word header). If it is at the end of the line, it is transferred to the beginning of the next line. This command is fast and can replace the l command.

B: move one word to the left. 2b: move two words to the left.

E, w, but the cursor stops at the end of the word.

Ge, the same as B, the cursor stops at the end of the word.

^ Move to the first non-blank character in the row.

0 (number 0) Move to the first character of the row,

<HOME> move to the first character of the row. Same as 0.

$ Move to the end of a row 3 $ move the cursor down 2 rows to the end of the row

Gg moves to the file header. = [[

G (shift + g) moves to the end of the file. =]

The f (find) command can also be used to move. fx finds the first character x after the cursor, and 3fd finds the third character d.

F is the same as f, and reverse lookup is performed.

(Commands f and F can only be searched in this row, but cannot find the content of other lines)

Jump to the specified row, colon + row number, and press Enter. For example, to jump to row 240, press ENTER 240. Another method is to jump to the row number + G, for example, 230G.

Ctrl + e scroll down a row

Ctrl + y scroll up a row

Ctrl + d scroll down the half screen

Ctrl + u scroll up half screen

Ctrl + f scroll down one screen

Ctrl + B scroll up one screen

SEARCH Command

/Text Search text, search for the next one by njian, and search for the previous one by njian.

? Text Search text, reverse search, search for the next one by the n key, and search for the previous one by the N key.

Some special characters in vim need to be escaped during search. * [] ^ % /?~ $ (Escape using)

: Set ignorecase case-insensitive search

: Set noignorecase case-insensitive search

Search for a long word. If a word is long and difficult to type, you can move the cursor over the word and press the * or # key to search for the word, which is equivalent to/search. And # The command is equivalent? Search.

: Set hlsearch highlights the search results. All results are highlighted, rather than displaying only one match.

: Set nohlsearch disable highlighted search display

: Nohlsearch disables the current highlight. If you search again or press the n or N key, it is highlighted again.

: Set incsearch gradually searches for the currently typed characters without waiting for the completion of the typing.

: Set wrapscan: Re-searches. When the file header or tail is searched, the system returns to continue searching. This function is enabled by default.

Replacement command

Ra replaces the current character with a, and the current character is the character where the cursor is located.

: S/old/new replace old with new, replace the first match of the current row

: S/old/new/g replace old with new, replace all matches of the current row

: % S/old/new replace old with new, replace the first match of all rows

: % S/old/new/g replace old with new, replace all the matches of the entire file

: 10th s/^ // g add four spaces in front of each line from 20th rows to rows for indent.

Ddp switches the row of the cursor and the row next to it. (A combination of dd and p commands)

Undo and redo

U Undo)
U undo the entire row
Ctrl + r Redo (Redo), that is, the Undo.

DELETE command (equivalent to cut)

X Delete the current character

3x Delete the current cursor starting with three characters backward

X deletes the first character of the current character. X = dh

Dl deletes the current character, dl = x

Dh deletes the first character, dh = X

Dd deletes the current row

Dj deletes the current row and the next row

Dk deletes the current row and the previous row

10dd Delete the 10 rows starting with the current row.

D. Delete the current character to the end of the line. D = d $

D $ Delete All characters after the current character (ROW)

: 1, 10 days delete 1-10 rows

: 11, $ d Delete 11 rows and all subsequent rows

: 1, $ d delete all rows

J (shift + j) deletes the spaces between the row and the next row. In fact, the two rows are merged.

Copy and paste

Yy copy the current row

Nyy copies the n rows starting from the current row, for example, 2yy copies the current row and the next row.

P is pasted after the current cursor. If you have used the yy command to copy a row, paste it in the next row of the current row.

Shift + p paste on the current row

: 20th co 20 insert 1-10 rows to rows.

: 1, $ co $ copy the entire file and add it to the end of the file.

In normal mode, press v (verbatim) or V (line-by-line) to enter the visual mode. Then, use the jklh command to move and select certain lines or characters. Then press y to copy them.

Ddp exchange the current row and next row

Xp exchanges the current character with the next character

Cut command

In normal mode, press v (verbatim) or V (line-by-line) to enter the visual mode. Then, use the jklh command to move and select certain lines or characters. Then press d to cut.

Ndd cut the n rows after the current row. The p command can be used to paste the cut content.

: 1, 10 days Cut 1-10 rows. The p command can be used to paste the cut content.

: 1, 10 m 20 move rows 1-10 to rows 20th

Exit command

: Wq save and exit

ZZ save and exit

: Q! Force exit and ignore all changes

: E! Discard all modifications and open the original file.

Comment command

In the perl program, # The Beginning of the behavior annotation, so to comment some rows, you only need to add at the beginning of the line #

: 3, 5 s/^/#/g comment line 3-5

: 3, 5 s/^ # // g uncomment 3-5 rows

: 1, $ s/^/#/g comment the entire document.

 

 

 

Image

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.