How to use VIM Edit command in Linux system

Source: Internet
Author: User

Using Linux, you don't have to deal with the editor. Linux systems have multiple editors, such as Nano,gedit,vi,vim. The Nano is simple and easy to use, but the function is relatively single. The VI command is powerful, but it may not be easy to get started. Vim is the enhanced version of VI command, generally using VIM command. Here's a brief list of the common uses of vim.

Vim is a full-screen editor, a modal editor. Mode mainly has edit mode, input mode, last line mode. The default is to open the VIM command to enter edit mode.

Open File Open file: Vim/path/to/somefile
Other uses:
Vim +#: Open the file and navigate to the # line
Vim +: Open the file and navigate to the last line
Vim +/pattern: Opens the file and navigates to the beginning of the line that was first matched by pattern

Close file 1, end line mode close file
: Q Do not save exit
: Wq Save and exit
: q! Do not save Force exit
: W Save
: w! Force Save
: Wq-->: X

2. Edit Mode exit
ZZ Save and exit

Mode conversion 1, edit--> input
I: Switch to input mode before the character at the current cursor;
I: Switch to input mode at the beginning of the character at the current cursor;
A: Switch to input mode after the current cursor's character;
A: Switch to input mode at the end of the line at the current cursor;
O: Creates a new row below the current cursor line, changing to input mode;
O: Creates a new row above the line on which the current cursor is positioned, changing to input mode;
2, Input--> edit
ESC key
3. Edit the last line of-->
:
4, the last line--> edit
ESC key

Move cursor (edit mode) 1, move cursor verbatim
H: Left
L: Right
J: Next
K: Upper

#h: Moving # Characters

2. Move words one by one
W: Move to the beginning of the next word
E: Move to the suffix of the current or next word
B: Move to the beginning of the current or previous word

#w: Support

3, in-line jump
0: Jump to the beginning of the line, absolute beginning
^: The first non-white-space character that jumps to the beginning of a line and the beginning of a line
$: Skip to end of line, absolute line end

4. Jump between rows
#G: Jump To Line #
G: Last line

In the last row mode, return directly to the trip number

Flip screen ctrl+f: Turn down one screen
Ctrl+b: Turn up one screen

Ctrl+d: Turn down half screen
Ctrl+u: Turn up half screen

Delete single character x: Deletes a single character at the cursor
#x: Delete The total # characters at the cursor and back

Combination of Delete command dd command and jump command
d$: Deletes all characters at the end of the line where the current cursor is positioned.
D0: Deletes all characters at the line cursor position to the beginning of the current cursor.
Dw
De
Db
DD: Deletes the current cursor in the row
#d跳转符:

Last line mode
. It means that when you move forward
$ represents the last line
+# down the # line
For example:
1,2d
., $d
., $-3d

Paste Command pp: If you delete or copy as an entire row, paste to the bottom of the line that contains the cursor, and if the copied or deleted content is not an entire row, paste to the back of the character that contains the cursor.
P: If you delete or copy the entire row, paste to the top of the line that contains the cursor, and if the copied or deleted content is not an entire row, paste to the front of the character that contains the cursor.

Copy command y usage same d command

Modify command c usage same d command

Replace rr@: Replace the character at the position of the cursor at the @ character

Revoke UU, the continuous u command can undo the previous n operations, generally save only 50 times.

Undo the most recent undo operation: Ctrl+r

Visual Mode V: selecting by character
V: Select by rectangle

You can use a variety of editing commands, such as the D command, to delete them.

Find/pattern: Start looking down from the current cursor position.
Pattern: Start looking up from the current cursor position.
N: The latter result
N: Previous result

Find replacement Use the s command in last line mode, same usage as SED

For example:
:., $-1s/he/he/g replaces all he in the current line to the penultimate line.

This is a common use of the Vim editor, which mainly describes the commands in edit mode. In the input mode, the Nano function is similar.

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.