Linux Learning Notes < 10 >--vim Editor

Source: Internet
Author: User
Tags exit in

Vi:visual Interface

Vim:visual Interface Improved


Vim mode:

Edit mode (Command mode): The mode in which Vim is turned on by default

Input mode

Last-line mode


Mode conversion:

Edit--Input:

I: In front of the character of the current cursor, switch to input mode;

A: After the character of the current cursor, switch to input mode;

O: At the bottom of the current cursor line, create a new row and switch to input mode;

I: Converted to input mode at the beginning of the line at which the cursor is currently located

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

O: At the top of the current cursor line, create a new row and switch to input mode;


Input-to-edit:

ESC key


Edit-to-last line:

: Key


Last line--edit

ESC key, ESC key

First, open the file

Vim/path/to/file

Vim +#: Open the file and locate it on line #

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

Vim +/pattern: Open the file and navigate to the beginning of the line that was first matched to the PATTERN


Second, close the file

1. Closing the file in the last line mode

: Q exit

: Wq Save and exit

: q! Do not save and exit

: W Save

: w! Forcibly saved

: x =: Wq


2. Exit in edit mode

ZZ: Save and exit


Third, move the cursor (edit mode)

1. Character-by-word movement

H: Left

L: Right

K: Up

J: Next

#[hlkj]: Move # Step


2. Move in Word units

W: Move to the beginning of the next word

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

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

#[web]


3. In-line jump

0: Jump to the absolute beginning

^: first non-whitespace character at the beginning of a line

$: Last character at end of line


4. Jump between rows

#G: Jump To Line #

G: Jump to the last line

GG: Jump to the first line

: #: The last line mode directly to the travel number can jump


Four, turn the screen

CTRL+F: Flip one screen down

Ctrl+b: Turn up one screen

Ctrl+d: Flip Down half screen

Ctrl+u: Flip Down half screen


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 Commands

D with jump command: D0,D^,D$,D#G,DG, remove from cursor position to jump position

D with move command: DW,DE,DB,DH,DL,DK,DJ, remove from cursor position to move position, DJ Delete cursor line and down line, DK function same

DD: Deletes the current cursor in the row

#dd: Delete the # line including the line where the current cursor is located

In the last line mode:

Startadd,endaddd

.: Indicates when the forward

$: Last line

+#: Down # line

The last deleted information can be used to paste


Seven, Paste command

P: If you delete or copy to an entire line, paste to the bottom of the line where the cursor is located, and if the deleted or copied content is a non-full row, paste it after the character that contains the cursor

P: If you delete or copy to an entire row, paste to the top of the line where the cursor is located, and if the copied or deleted content is a non-full row, paste it in front of the character in the cursor;


Viii. Copying commands

Y: Usage with d command


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

C: Usage with d command


X. replacement

R character: replaces the single character indicated by the cursor

R character: replaces the single character indicated by the cursor, and then enters the input mode


Xi. Undo Edit Operation Undo

U: Undo the previous edit operation

Continuous U-command to undo previous N Edit operations

#u: Undo Recent # edits directly


12. Repeat the previous edit operation

.


13, Visual mode, the cursor selection of the specified range

V: Individually selected by character or line

V: Select by rectangle


14. Find

/pattern: Find from the current cursor line to the end of the file

? PATTERN: Search from the current cursor line to the file header

N: Skip to Next

N: Skip to Previous


XV, find and replace

Use the S command in the last-line mode

: Addr1,[email Protected]@[email protected]

., $ represents the current line from the cursor to the last row

%: Full text


16. Use Vim to edit multiple files

Vim File1,file2,file3

: Next switches to the next file

:p Rev Switch to the previous file

: Last switch to first file

: first to switch to file one

: QA All exits


17. split Screen Display file

Ctrl+w-->s: Horizontal splitter window

Ctrl+w-->v: Vertical splitter window


18. Edit multiple files in a window

Vim-o File1,file2 ... : Horizontal Split Display

Vim-o File1,file2 ... : Vertical Split Display


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

Use the W command in the last row mode

: Addr1,addr2w/path/to/file


20. Fill the contents of another file under the current file cursor

: R/path/to/file


21. Interacting with the shell

:! COMMAND


22. Advanced Topics

: Set number <-->: Set NU Displays line numbers

: Set Nonu suppress line numbers

: Set ignorecase <--> set IC ignore case when searching

: Set Noic Ignore case when search is canceled

: Set autoindent <-->: Set AI settings Auto indent

: Set Noai Cancel Auto Indent

: Set Hlsearch to find text highlighting

: Set Nohlsearch Suppress highlighting

: Syntax on start syntax highlighting

: Syntax off to cancel syntax highlighting


23. Configuration Files

/etc/vimrc

~/.vimrc




Linux Learning Notes < 10 >--vim Editor

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.