Vim in the Save and exit, Vim quit command, how to exit Vim Editor, vim command Daquan __vim

Source: Internet
Author: User
Tags save file perl script


Exit command is, press ESC to jump to command mode, and then enter: Q (not saved) or: Wq (save) exit. more exit Commands:

: w save file but not exit VI
: W file will be modified to save in file, do not exit VI
: w! Mandatory save, do not launch VI
: Wq save file and Exit VI
: wq! Force file to save and Exit VI
: Q Do not save files, exit VI
: q! Do not save file, Force exit VI
: e! Discard all modifications and edit command history from the last save file

Commands with: and/start with history, you can first type: or/And 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 command named filename

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, and the files currently being edited are enclosed in [].

: args

Open a remote file, such as FTP or share folder

: E

: E \qadrive\test\1.txt vim mode

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

I inserted before the current position
I inserts at the beginning of the current line
A inserts after the current position
A inserts at the end of the current line
o Insert a row after the current line
O Insert a line Lookup command before the current line

/text find text, press N to find Next, and press N to find the previous one.
? text find text, reverse lookup, press N to find Next, press N to find the previous one.

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

: Set ignorecase Ignore Case lookup
: Set noignorecase do not ignore case-insensitive lookups

Look for long words, if a word is very long, typing trouble, you can move the cursor to the word, press * or # key that word can be searched, the equivalent of/search. And the # command is equivalent to a search.

: Set Hlsearch Highlight search results, and all results are highlighted rather than just one match.
: Set Nohlsearch off highlight search display
: Nohlsearch closes the current highlight, and if you search again or press N or N, it will be highlighted again.
: Set Incsearch a step-by-step search pattern that searches for the characters currently typed without having to wait for typing to complete.
: Set Wrapscan to search again, when searching to the header or tail of the file, return to continue the search, the default to open. Replace command

The RA replaces the current character with a, where the period character is the character of the cursor.
S/old/new/replaces new with old, replaces the first match of the current line
S/old/new/g replaces new with old, replaces all matches for the current line
%s/old/new/replaces new with old, replaces the first match for all rows
%s/old/new/g replaces new with old and replaces all matches for the entire file
: 10,20 s/^//g in line 10th know the 20th line in front of each line plus four spaces, for indentation.
The DDP exchange cursor is in line with the row immediately below it. Move Command

H move one character to the left
L Move one character to the right, this command is rarely used and is generally replaced with W.
K Move one character up
J Move one character down

The above four commands can be used with digital, such as 20J is to move down 20 lines, 5h is to move to the left 5 characters, in vim, many commands can be used with digital, such as the deletion of 10 characters 10x, in the current position after inserting 3. , 3a. , the ESC is required here, otherwise the command does not take effect.

W moves one word forward (the cursor stops at the word header), and if it is at the end of the line, go to the beginning of the next line. This command is quick and can replace the L command.
b Move one word back 2b move 2 words back
E, same w, just the cursor stops at the end of the word
GE, with B, the cursor stops at the end of the word.
^ Move to the first non-white-space character on the bank.
0 (the number 0) moves to the first character of the Bank,
Move to the first character in the line. With 0 kin.
Move to end of line 3 move to end of line 3 move to bottom of line 3
GG moves to the header of the file. = [[
G (Shift + g) moves to the end of the file. = ]]
The f (find) command can also be used to move, FX will locate the first character after the cursor, and the 3FD will find the third character for D.
F with F, reverse lookup.

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

Ctrl + e scroll down one line
Ctrl + y scroll up one line
Ctrl + D scroll down 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 (undo)
U undo action on Whole line
Ctrl + R Redo (Redo), that is, undo revocation. Delete command

X Delete Current character
3x Delete current cursor start backwards three characters
X deletes the previous character of the current character. X=dh
DL deletes the current character, dl=x
DH Deletes the previous character
DD Delete when forward
DJ Deletes previous line
DK Delete Next Line
10d deletes 10 lines starting at the current line.
D deletes the current character to the end of the line. D=d d d deletes all characters after the current character (bank)
KDGG all rows (excluding current rows) before the current row is deleted
JdG (JD Shift + G) deletes all rows after the current line (excluding current rows)
: 1,10d Delete 1-10 lines
: one, D delete 11 lines and all subsequent lines: 1, D delete 11 lines and all subsequent lines: 1,d Delete all rows
J (Shift + J) deletes the blank line between the two lines, actually merging the two rows. Copy and paste

YY copy when moving forward
Nyy copies the current start of n lines, such as the 2yy copy of the current line and its next line.
P Pastes after the current cursor, if the YY command was used to copy a row, then the next line in the current row is pasted.
Shift+p Paste before current line
: 1,10 Co 20 inserts 1-10 rows after line 20th.
: 1, CO Co copies a copy of the entire file and adds it to the tail of the file.

In normal mode, press V (verbatim) or V (line by row) into visual mode, then move with the JKLH command to select some rows or characters, and then press Y to copy

DDP Exchange Current line and its next line
XP swaps the current character and the following character cut command

In normal mode, press V (verbatim) or V (line by row) into visual mode, then move with the JKLH command to select some rows or characters, and then press D to cut

NDD cut n rows after the current row. Use the P command to paste cut content
: 1,10d will cut 1-10 lines. Use the P command to paste the cut content.
: 1 m 20 moves the 第1-10 line after line 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 window where the cursor stops at the top window
: Split files or: New file opens with a newer window
Split open windows are horizontal, using Vsplit to open the window vertically.
CTRL+WW move to the next window
CTRL+WJ move to the bottom of the window
Ctrl+wk move to the top window close the window

: The last window of close cannot use this command to prevent an unexpected exit from Vim.
: Q If it is the last window to be closed, then the vim will be exited.
ZZ Save and exit.

Closes all windows, leaving only the current window

: Only record macros

Press Q and add any letter to start recording, and then press Q to end recording (this means that the macro in Vim can not be nested), when used @ Add macro name, such as QA ... Q record A macro named A, @a use this macro. Execute shell Command

:!ls list files in current directory
:!perl-c Check the Perl scripting syntax, and it's easy to quit Vim.
:!perl to execute Perl scripts, which can be very handy without exiting Vim.
: Suspend or Ctrl-z hang vim, back to the shell, according to FG can return vim. Comment Command

The behavior annotation in the Perl program # starts, so to annotate some lines, just add the # at the beginning of the line

3,5 s/^/#/g annotation 第3-5 line
3,5 s/^#//g 3-5-line Comment
1,$ s/^/#/g annotate the entire document.
:%s/^/#/g annotate the entire document, this method is faster. Help Commands

: Help or F1 displays the entire aid
: Help XXX Displays the assistance of XXX, such as: Help I, helping ctrl-[(that is, ctrl+[).
: Help ' number ' vim option is enclosed in single quotes
: Help special key helps with <> expansion
: help-t Vim startup parameters for help-
: Help I_ ESC in insert mode, mode for help in a pattern _ theme

The Help file is located in | | The content between is a hyperlink, you can use CTRL +] to enter the link, ctrl+o (Ctrl + t) return to other non-edit commands

. Repeat previous command

: Set ruler? Check to see if ruler is set, in. VIMRC, options that are set by using the SET command can be viewed through this command
: Scriptnames View the location of the Vim script file, such as. vimrc files, grammar files, and plugin.
: The set list displays nonprinting characters, such as tab, space, line footer, and so on. If tab cannot be displayed, make sure the. vimrc file is set with the set lcs=tab:>-command, and make sure that you have tab in your file, and that if Expendtab is turned on, the tab will be expanded to a space. Vim Tutorial

On the UNIX system

$ vimtutor

On the Windows system

: Help Tutor


: syntax list already defined syntax entries
: syntax clear clears the defined syntax rules
: syntax case match case-sensitive, int and int will be treated as different syntactic elements
: syntax Igno Re case-insensitive, int and int will be 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: 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.