Vim Command Collection

Source: Internet
Author: User
Tags perl script

Command History

Commands with: and/begin with a history, you can first type: or/Then press the up and down arrows to select a history command.

start Vim

Enter the following command in the Command line window

Vim starts vim directly

Vim filename opens vim and creates a file named filename

file Commands

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

: BP

View the list of currently open files, enclosed in [] for the file you are currently editing.

: args

Open remote files, such as FTP or share folder

: E ftp://192.168.10.76/abc.txt

: E \\qadrive\test\1.txt

Vim's mode

Normal mode (press ESC or ctrl+[) the lower-left corner displays the file name or is empty
Insert mode (press the I key to enter) the lower left corner shows--insert--
Visual mode (do not know how to enter) the lower left corner shows--visual--

Navigation Commands

% brackets Match

Insert Command

I inserted at the current position

I Insert at the beginning of the current

A is inserted after the current position

A inserts at the end of the current line

o Insert a row after the current line

O insert a row before the current line

Find Command

/text find text, press N to find the next, press N to find the previous one.

? text find text, reverse lookup, press N to find the next, press N to find the previous one.

There are some special characters in vim that need to be escaped when searching. *[]^%/?~$

: Set ignorecase ignores case-finding

: Set noignorecase does not ignore case-finding

Look for long words, if a word is very long, type trouble, you can move the cursor to the word, press the * or the # key to be able to search the word, equivalent/search. and the # command corresponds to a search.

: Set Hlsearch Highlight search results, all results are highlighted instead of just one match.

: Set Nohlsearch Close Highlight search display

: Nohlsearch turns off the current highlight, and if you search again or press N or N, it will be highlighted again.

: Set Incsearch stepwise search mode to search for characters that are currently typed without waiting for typing to complete.

: Set Wrapscan re-search, when searching to the head or end of the file, return to continue the search, by default open.

Replace command

The RA replaces the current character with a, when the period character is the character of the cursor.

s/old/new/replace new with old, replacing the first match of the current row

s/old/new/g replace new with old, replacing all occurrences of the current row

%s/old/new/replace new with old, replacing the first match of all rows

%s/old/new/g replace new with old, replacing all occurrences of the entire file

: 10,20 s/^//g adds four spaces before each line in line 10th to indent.

DDP swaps the line that the cursor is in and immediately below it.

Move Command

H move one character to the left
L Move one character to the right, this command is seldom used and is usually replaced by W.
K Move up one character
J Move down one character
The above four commands can be used with the number, such as 20J is to move down 20 lines, 5h is to move 5 characters to the left, in vim, many commands can be used with the number, such as delete 10 characters 10x, after the current position after inserting 3! , 3a! <esc>, the ESC here is required, otherwise the command does not take effect.

W moves forward one word (the cursor stops at the beginning of the word), and if it is at the end of the line, go to the start of the next line. This command is fast and can replace the L command.

b Move backward one word 2b move backwards 2 words

E, with W, except that the cursor stops at the tail of the word.

GE, with B, the cursor stops at the end of the word.

^ Moves to the first non-whitespace character of the bank.

0 (number 0) moves to the first character of the Bank,

<HOME> moves to the first character of the bank. With 0 kin.

$ move to end of line 3$ move to line end below 3 lines

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, and FX will find the first character that is x after the cursor, and 3FD will find the third character of D.

F with F, reverse lookup.

Jump to the specified line, colon + line number, enter, such as jump to 240 line is: 240 back to the car. Another method is the line number +g, such as 230G jumps to 230 rows.

Ctrl + E scrolls down one line

Ctrl + y scrolls up one line

Ctrl + D scroll down half screen

Ctrl + u scroll up half screen

Ctrl + F scroll down one screen

Ctrl + B scrolls up one screen

Undo and Redo

U undo (undo)
U undo the operation of the whole row
Ctrl + R Redo (Redo), that is, undo revocation.

Delete command

X Delete Current character

3x Delete current cursor start backward three characters

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

DL Delete current character, dl=x

DH Deletes a previous character

DD Delete When moving forward

DJ Delete Previous Line

DK Delete Next Line

10d deletes 10 rows from the beginning of the current line.

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

d$ Delete all characters after the current character (bank)

KDGG all rows before the current row is deleted (excluding the current row)

JdG (JD Shift + G) deletes all rows after the current line (excluding the current row)

: 1,10d Delete 1-10 rows

: One, $d delete 11 rows and all subsequent rows

: 1, $d delete all rows

J (Shift + J) Deletes a blank line between two rows, in effect merging two rows.

Copy and paste

YY copy when moving forward

Nyy copies the current row of n rows, such as 2yy to copy the current line and its next row.

P is pasted after the current cursor, and if you have previously used the YY command to copy a row, paste it on the next line of the current row.

Shift+p pasting before the current line

: 1,10 Co 20 inserts 1-10 rows after the 20th row.

: 1,$ Co $ copies a copy of the entire file and adds it to the end of the file.

In normal mode, press V (verbatim) or V (Progressive) to enter the visual mode, then move with the JKLH command to select some rows or characters, then press Y to copy

DDP swaps the current row and its next row

XP swaps the current character and a subsequent character

Cut Command

In normal mode, press V (verbatim) or V (Progressive) to enter the visual mode, then move with the JKLH command to select some lines or characters, then press D to cut

NDD cuts the n rows after the current line. Use the P command to paste the clipped content

: 1,10d will cut 1-10 rows. Use the P command to paste the clipped content.

: 1, ten M 20 move the 第1-10 line after the 20th line.

Exit Command

: Wq Save and exit

ZZ Save and exit

: q! Force exit and Ignore all changes

: e! Discard all changes and open the original file.

window Commands

: Split or new opens a new window with the cursor hovering over the top-level window

: Split file or: New to open the files in a fresh window

Split opens a window that is horizontal and uses 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 top window

Close window

: Close last window cannot use this command to prevent accidental exit of vim.

: Q If it is the last window to be closed, VIM will exit.

ZZ Save and exit.

Close all windows, leaving only the current window

: Only

Recording a macro

Press Q to start recording with any letter, then press Q to end the recording (this means that the macros in Vim are not nested), when using the @ Add macro name, such as QA ... Q record A macro named A, @a use this macro.

Execute shell Command

:!command

:!ls lists the files in the current directory

:!perl-c script.pl Check perl script syntax, it is very convenient without having to quit vim.

:!perl script.pl Executes Perl scripts and is very handy without having to exit vim.

: Suspend or Ctrl-z hangs vim, returns to the shell and presses FG to return to vim.

Comment Commands

In the Perl program, the # starts the behavior comment, so to comment on some lines, just add # at the beginning of the line

3,5 s/^/#/g Comment 第3-5 line

3,5 s/^#//g dismiss 3-5 lines of comment

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

:%s/^/#/g comments The entire document, this method is faster.

Help Commands

: Help or F1 show the whole aid
: Help XXX shows the assistance of XXX, such as: Help I, ctrl-[(ie, ctrl+[).
: Help ' number ' vim option is enclosed in single quotes
: Help <Esc> Special Keys <> expand
: help-t vim start parameter help with-
: Help i_<esc> mode for help with ESC in insert mode, a mode with mode _ theme
The Help file is located in the | | The content between is a hyperlink, you can use CTRL +] to enter the link, ctrl+o (Ctrl + t) return

other non-editing commands

. Repeat the previous command

: Set ruler? To see if ruler is set, in. VIMRC, the option to use the SET command can be viewed by this command

: Scriptnames View the location of Vim script files, such as. vimrc files, grammar files, and plugin.

: Set list displays nonprinting characters, such as tab, space, end of line, and so on. If the tab cannot be displayed, make sure the. vimrc file is set with the set lcs=tab:>-command, and make sure that your file has a tab, and if Expendtab is turned on, tab will be expanded to a space.

Vim Tutorials
On UNIX Systems
$ vimtutor
On a Windows system
: Help Tutor

: syntax lists syntax items that have already been defined
: syntax clear clears the defined grammar rules
: syntax case match casing sensitive, int and int will be treated as different syntax elements
: syntax case ignore uppercase and lowercase, int and int will be treated as the same syntax element and use the same color scheme

Vim Command Collection

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.