Vim Editor Detailed

Source: Internet
Author: User

Vi:visual Interface

Vim:vi improved

Vim is a full-screen editor and a modal editor


Vim mode:

Edit mode (Command mode)

Input mode

Last-line mode

Mode conversion: Default is in command mode

Command--Input:

I: Inserted in front of the character that the current cursor refers to, into input mode

A: Inserted after the current cursor character, converted into input mode

O: Under the current cursor line, create a new row and switch to input mode:


I: Switch to input mode at the beginning of the line where the cursor is currently located

A: At the end of the line where the current cursor is located, switch to input mode

O: Create a new row above the current cursor and switch to input mode


Input/Last line--edit

ESC or Esc+esc (sometimes two required)


Edit-to-last line

Input: Can


First, open the file:

Vim/path/to/somefile

Vim +#: Open the file and navigate to line #

Vim +: Open the file and navigate to the last line

Vim +/pattern: Open the file and navigate to the line that was first matched to by Parttern


Second, close the file

In the last line mode:

: Q Exits but does not save

: W Save

: Wq Save and exit--equivalent to: X

: q! do not save and exit

: w! Forcibly saved


In edit mode:

ZZ: Save and exit


Third, move the cursor (edit mode)

Character-by-word movement:

H: Left

J: Next

K: Up

L: Right

#h: Moving a # character


Move in a word unit

W: Move to the beginning of the next word

E: Jumps to the ending of the current or next word

B: Jump to the beginning of the current or previous word

#w: Moving # words

In-line jump:

0: Jump to the absolute beginning

^: The first non-whitespace character in front of the beginning of a line

$: absolute end of line


Inline jump

#: Jumps from the current position # line, if the current position is less than the # line at the end of the line, then jumps to the end of the line

#G: Jump To Line #

G: Last line

In the last line mode, directly to the travel number can be



Four, turn the screen

Ctrl+f: Turn down one screen (f can be used as a forward for memory convenience)

Ctrl+b: Turn up one screen (backward)


Ctrl+d: Turn down half screen (down)

Ctrl+u: Flip up half screen (UP)


V. Delete a single character

X: Delete a single character at the cursor location

#x: Remove the total # characters from the cursor and backwards


Vi. Delete command: D

The D command is used in combination with the jump command:

#dw, #e, #db

DD: Deletes the current cursor in the row

#dd: Delete current cursor and down total # lines


In the last line mode:

Startline,endlineD

.: Indicates when the forward

$: Indicates the last line

+#: Down # line


Seven, paste, command p

P: If you delete or copy the entire line, paste it below the line where the cursor is located, and if it is not a whole line, paste it after the character of the cursor

P: If you delete or copy the entire line, paste it above the line where the cursor is located, and if it is not a whole line, paste it in front of the character of the cursor


Eight, copy command y

Usage with D


Nine, modify: First delete the content, and then into the input mode

C: Use with D


X. Replacement: R

R: Replacement mode


Xi. Undo the previous edit Operation U

U: Undo the previous edit operation

Successive U-commands can undo previous n operations

#u: Undo Recent # Operations directly


12. Repeat the previous edit operation

.


13. Visualization Mode

V: Select by character

V: Select by rectangle


14. Find

/pattern

? pattern

N: Look down

N: Find up


XV, find and replace

Use the S command in the last-line mode

Addr1,addr2s/pattern/string/gi

1,$

%: Full text


16. Use Vim to edit multiple files

Vim file1 file2 File3

: Next switches to the next file

: prev Switch to previous file

: Last switch to final file

: first to switch to file one


Exit

: QA All exits


17, split screen display a file

Ctrl+w,s: Horizontal splitter window

Ctrl+w,v: Vertical splitter window

Toggle the cursor between windows

Ctrl+w,arrow (i.e. arrow key)

(Press the Key method is the first ctrl+w double-click, then the single well W, v ...)

: QA Closes all windows


18, sub-Windows multiple files

Vim-o: Horizontal Split display

Vim-o: Vertical Split display


19. Save some of the contents of the current file as a different file

: W

: Add1,add2w/path/to/file


20. Populate the contents of another file in the current file

: R/path/to/somefile


21. Interacting with the shell

:! COMMAND


22. Advanced Topics

Show or suppress line numbers

: Set Number

: Set Nonu (the command can be abbreviated, as long as it is unique)


Show ignore or differentiate character case

: Set ignorecase

: Set Noic


Set Auto Indent

: Set Autoindent

: Set Noai


Find text to highlight or cancel

: Set Hlsearch

: Set Nohlsearch


Syntax highlighting

: Syntax on

: Syntax off


23. Configuration Files

/etc/vimrc

~/.vimrc


24, if the abnormal exit or the simultaneous editing of multiple people will appear similar to the following prompt:

E325:attention

Found a swap file by the name ". My.cnf.swp"

Owned By:root Dated:thu Jan 14 15:31:21 2016

File name:/tmp/my.cnf

Modified:no

User Name:root host Name:logstash

Process id:3055 (still running)

While opening file "My.cnf"

Dated:thu Jan 14 10:44:10 2016


(1) Another program may editing the same file. If This is the case,

Be careful is different instances of the same

file when making changes. Quit, or continue with caution.

(2) An edit session for the this file crashed.

If This is the case, use ": Recover" or "vim-r my.cnf"

To recover the changes (see ": Help Recovery").

If you do this already, delete the swap file ". My.cnf.swp"

To avoid the this message.

You can simply delete files with the file name in the same directory as. filename.swp files. FileName refers to the name of the file being edited.



This article is from the "single Season rice" blog, please be sure to keep this source http://linzb.blog.51cto.com/5192423/1734609

Vim Editor Detailed

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.