--vim Foundation of Linux operation and maintenance learning

Source: Internet
Author: User
Tags delete key

Common options for the Vim text editor under Linux.

VIM (Visual interface improved) is an enhanced version of the VI editor, small but powerful, is the most frequently used Linux system Text editor, so learning Vim is also a necessary skill to learn Linux!

VIM's command format:

vim [options] [File ...]

eg

[Email protected] ~]# vim hello.txt    #用vim打开hello. txt file

Vim opens the file with the default mode of edit mode (also called command mode).

Edit mode (Command mode) commonly used keys:

by moving the keyboard on the h (←), J (↓), K (↑), l (→) to move the cursor, can also be used with the number keys

Eg:#+ the arrow key to move the # characters in the direction indicated by the direction key.

It's a bit cumbersome to move the cursor with the HJKL or arrow keys alone, or you can use the W,e,b three buttons to Word Jump .

W: Jumps to the beginning of a word after the cursor;

E: Jumps to the current or next word ending;

B: In contrast to E, jump to the beginning of the current or previous word;

Similarly, w,e,b can also be used with a numeric key, which means jumping to n words in a certain way.

Another common in-line jump command also has

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

0: The absolute beginning

$: End of line

If you jump between rows, use G

1g,gg: Can quickly jump from the middle of the file or the tail of the file to the first line of the file;

G: fast-read jump to the last line of the file

#G: With digital use, you can quickly specify a jump to the # line of the file.

To view files with more content, you can use the Flip screen key to view

Flip screen Forward: ctrl+f (forward);

Flip the screen backwards: ctrl+b (back);

You can also flip the contents of a half screen at a time

Half-screen forward: ctrl+u (UP)

Half-screen back: Ctrl+d (down)

Edit mode support Copy, delete, paste (the last time you delete the content can be pasted out)

Delete Key has X,d,c

X: Delete the single character where the cursor is located;

NX: Delete the right n characters at the cursor location

D Delete key can be used with w,e,b word jump. Delete a word forward or backward, but be aware that deleting the current cursor will not delete the character! The commonly used D keys are:

Dw,de,db #注意往前删不会删除当前光标所在字符

DD: Delete cursor in the row

NDD: Removes the line with the cursor and the down n rows #包括光标所在的行

cc: Delete current line and convert into input mode #其他使用方法c^ c0 CW cd CE

The copy key is Y (Yank), usage

YY: Copy one line

#yy: Copy # lines

y$: Copy cursor to end of line

y^: Copy cursor to beginning of line

After the copy is pasted out, paste the key is P (p) [p for Paste,put], it is worth noting that the last delete of D can also be pasted out by P (p)!

If a whole row is copied and deleted, then

P (lowercase): Paste below the line where the cursor is located

P (Uppercase): Paste above the line where the cursor is located

If you copy, delete not a whole line, then

P (lowercase): Paste after the character of the cursor

P (Uppercase): Paste in front of the character in which the cursor is located

If you want to undo an operation accidentally, you can use the U key

U: Press once to undo the last operation, multiple times u can undo multiple operations.

Accidentally revoked the correct operation? OK, undo action can also be undone ...

Ctrl+r: Undo the last undo operation of the previous time.

In edit mode, press V (v) to enter the visual mode )

V, select the character that the cursor is in, with copy, paste use

V, select the line across the cursor, with copy, paste using

Press CTRL + V You can also select each row of the column as the unit of content, with copy, paste using

Now that you're done with the usual keys for edit mode, it's time to enter input mode from edit mode (insert mode)

I:insert, inserted before the character where the current cursor is located

I: Inserted at the beginning of the line where the cursor was before

A:append, inserted after the character where the current cursor is located

A: The end of the line where the cursor is inserted

O: New blank line below cursor line

O: Insert above the line where the cursor is located

Press the ESC key in input mode to return to edit mode!

Edit Mode Press: Can enter the last line mode, the input mode will need to press ESC to return to edit mode, press: Enter the last line mode.

The commands commonly used in the last-line mode are:

: w #保存编辑的内容

: Q #退出而不保存

:! #强制, for example: w! forced save,: q! Force exit

: Wq #保存退出

: X #退出

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.