Vim command collection

Source: Internet
Author: User
Tags printable characters perl script


Command history

Commands starting with ":" and "/" have historical records. You can first type ":" or "/" and then press the up or down arrow to select a historical command.

Start vim

Enter the following command in the command line window:

Vim directly starts vim

Vim filename open vim and create a file named filename

FILE command

Open a single file

Vim file

Open multiple files at the same time

Vim file1 file2 file3...

Open a new file in the vim window

: Open file

Open a file in a new window

: Split file

Switch to the next file

: Bn

Switch to the previous file

: Bp

View the list of currently opened files. The files being edited are included in.

: Args

Open a remote file, such as ftp or share folder.

: E ftp: // 192.168.10.76/abc.txt

: E \ qadrive \ test \ 1.txt

Vim Mode

In normal mode (Press Esc or Ctrl + [enter). The file name is displayed in the lower left corner or is empty.
INSERT mode (press the I key to enter) display in the lower left corner -- INSERT --
VISUAL mode (do not know how to enter) display in the lower left corner -- VISUAL --

Navigation command

% Matching brackets

INSERT command

I insert before the current position

I insert at the beginning of the current row

Insert a after the current position

A is inserted at the end of the current row.

O insert a row after the current row

O insert a row before the current row

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. * [] ^ % /?~ $

: 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 new with old to replace the first match of the current row

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

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

% S/old/new/g Replace new with old, replace all matching

: 10, 20 s/^ // g add four spaces in front of each row in 10th rows to indent.

Ddp switches the row of the cursor and the row next to it.

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.
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, you can delete 10 characters (10 x) and insert 3 after the current position !, 3a! <Esc>, the Esc here is required, otherwise the command does not take effect.

W moves a word forward (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 backward. 2b: move two words backward.

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 to the end of the following three rows

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.

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

Undo and redo

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

DELETE command

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 previous character

Dd deletes the current row

Dj deletes the previous row

Dk deletes the next row

Delete 10 rows starting with the current row within 10 days.

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

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

Kdgg deletes all rows before the current row (excluding the current row)

JdG (jd shift + g) deletes all rows after the current row (excluding the current 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 empty rows between two rows, which are actually 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 in front of 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.

Window command

: Split or new opens a new window, And the cursor stops at the top-level window

: Split file or: new file open the file in a new window

The split window is displayed horizontally. You can use vsplit to open the window vertically.

Ctrl + ww move to the next window

Ctrl + wj move to the window below

Ctrl + wk move to the window above

Close Window

: You cannot use this command to close the last window to prevent accidental exit of vim.

: Q if it is the last closed window, it will exit vim.

ZZ save and exit.

Close all windows and keep only the current window

: Only

Recording macro

Press the q key and add any letter to start recording, and then press the q key to End recording (which means That Macros in vim cannot be nested). When using the q key, @ add macro name, such as qa... Q: The recording name is a macro. @ a uses this macro.

Execute shell commands

:! Command

:! Ls to list files in the current directory

:! Perl-c script. pl check the perl script syntax. It is very convenient to exit vim.

:! Perl script. pl: It is very convenient to execute a perl script without exiting vim.

: Suspend or Ctrl-Z suspends vim and returns to shell. Press fg to return vim.

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.

: % S/^/#/g to comment out the entire document. This method is faster.

Help commands

: Help or F1 displays the entire help
: Help xxx displays the help of xxx, for example: help I,: help CTRL-[(that is, Ctrl + [help ).
: Help 'number' the Vim option is enclosed in single quotes
: Help <Esc> help for special keys <> Expand
: Help-t help for Vim startup parameters-
: Help I _ <Esc> help of Esc in insert mode, help mode in a mode _ TOPIC Mode
The content in the Help file is a hyperlink. You can press Ctrl +] to enter the link, and press Ctrl + o (Ctrl + t) to return

Other non-edit commands

. Repeat the previous command

: Set rtasks? Check whether rsequence is set. In. vimrc, you can use this command to view the set options.

: Scriptnames: view the location of the vim script file, such as The. vimrc file, syntax file, and plugin.

: Set list displays non-printable characters, such as tab, space, and end of line. If the tab cannot be displayed, use the set lcs = tab:>-command to set it. vimrc file, and make sure that there is a tab in your file. If expendtab is enabled, the tab will be expanded to a space.

Vim tutorial
On Unix systems
$ Vimtutor
On Windows
: Help tutor

: Syntax list defined syntax items
: Syntax clear defined syntax rules
: Syntax case match is case sensitive. int and Int are considered different syntax elements.
: Syntax case ignore is case-insensitive. int and Int are treated as the same syntax elements and use the same color scheme.

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.