Vim Common commands

Source: Internet
Author: User
Tags perl script

VI into VIM, the following # number indicates the number

FullselectedThe correct answer is:
Ggvg
Explain the above command a little bit.
GG lets the cursor move to the first line,VimOnly valid, VI invalid
V is entering visual (visual) mode
G cursor moves to the last line
When selected, it is possible to do something else, such as:
D Delete Selection
Y copyselectedContents to register No. No. 0
The +y copyselectedThe contents to the + register, which is the clipboard of the system, for other programs

VI into VIM, the following # number indicates the number

Start in command line mode
Input->i at the cursor, enter the insert mode, if you press ESC to exit the Insert mode, enter the command line mode, you can enter the relevant command to operate
I Insert at the beginning of the current
Once again into insert mode, you can append content after the cursor->a
A inserts at the end of the current line
Insert a new line in the next line->o
Insert a new line in the previous line->o

Exit and save the file
: w filename. suffix name, then enter (enter W filename to save the article in the format specified by the file name Filename.txt.
: W, then enter (enter: W, then enter, save the file without exiting)
: Wq, then enter (enter: Wq, then enter, save and exit)
: q!, and then enter (enter: q!, and then enter, do not save the mandatory exit VI)
: e!, discard all changes, and open the original file

Move
HJKL, control the cursor to the left, bottom, top, and right one grid, or you can use four arrows
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&gt, the ESC here is required, otherwise the command does not take effect.
Press GG to move to the file header
G, move to end of file
Jumps to the specified row
#gg, for example, 15GG, moves the cursor to the beginning of the 15th line of the article.
Press the number 0 to move to the wardrobe.
^: first non-whitespace character starts
$: Moves to the end of the line.


Press CTRL+B, and the screen moves to "back" one page.
Press CTRL+F, and the screen moves to "front" one page.
Press Ctrl+u, and the screen moves half a page toward the back.
Press Ctrl+d, and the screen moves half a page toward the front.
Ctrl+e Scroll down one line
Ctrl+y scroll up one line
Press W, the cursor jumps to the beginning of the next word
Press E, the cursor jumps to the end of the word
Press B, the cursor returns to the beginning of the word.


Delete
X, each time you press, deletes a character at the cursor location.
#x, for example, 6x means to delete the "back" 6 characters that include the cursor position.
x, uppercase X, each time you click, delete the "front" character at the cursor location.
#X, for example, 20X means to delete the "front" 20 characters where the cursor is located.
DD, delete the line where the cursor is located.
#dd, delete the # line starting at the line where the cursor is located
DL deletes the current character, equivalent to X
DH Deletes the previous character, equivalent to X
DJ Delete below 2 lines
DK Delete above 2 lines
10DD 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 Delete all rows after the current row (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 deletes a blank line between two rows, in effect merging two rows.


Copy
YW, copies the character at the end of the cursor to the buffer.
#yw, copy # words to Buffer
YY, the copy cursor is located in the row to the buffer.
#yy, for example, 6YY means that the copy is "down" 6 lines of text from the line where the cursor is located.
P, paste the characters in the buffer to the next line where the cursor is located. Note: All copy commands related to "Y" must be mated with "P" to complete the copy and paste function.
P uppercase P is pasted on the current line on a 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.

Replace
R to replace the character at which the cursor is located.
R, replacing the character where the cursor is located until the ESC key is pressed.
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.
Change
CW, change the word at the end of the cursor


Redo/Undo/redo Last action
u, if a command is executed by mistake, you can press U immediately to undo the last action. Press multiple times "U" to perform multiple undo.
U undo the operation of the whole row
Ctrl+r Redo (Redo), which is the revocation of revocation.

Find
/keyword, first press/key, then enter the character you want to look for, if the first keyword is not what you want, you can always press N will look back to find the keyword you want.
keyword, first press the key, then enter the character you want to look for, if the first keyword is not what you want, you can always press N will look forward to the keyword you want.
n, used with/or, if the search is not the keyword you want to find, press N or backward (with/to) or forward (with) to continue looking until you find it.
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.
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.

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.
: 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.

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.tx

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.

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 is 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 Expandtab is turned on, tab will be expanded to a space.
$ 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
Before using last line mode, remember to press the ESC key to confirm that you are already in command mode, and then press: the colon to go to end line mode.
A) List line numbers
: Set Nu, after you enter set NU, the line number is listed before each line in the file.
B) Jump down a few lines
: #, #号表示一个数字, enter a number after the colon, then press ENTER to jump to the line, such as enter the number 3, and then enter, will jump to the 3rd row.

Vim Common commands

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.