Vim editor operations and Vim editor operations

Source: Internet
Author: User

Vim editor operations and Vim editor operations

1. vi Operation Mode

Vi provides two operation modes: insert mode and command mode ). In input mode, you can enter text. In command mode, you can perform various editing actions, such as deletion and modification.

In input mode, Press Esc to switch to command mode.

In command mode, press the input command (I, a, o, etc.) to enter the input mode.

 

2. Access vi

$ Vi filename

Directly type "vi + file name to be edited" to edit the specified file.

If the specified file is a New file, the system prompts "New file". Otherwise, the current content of the file is displayed.

$ View filename

Open File filename in read-only mode

 

Three-Instruction Mode

3.1 enter input mode

A is input after the current cursor

A is input at the end of the current row

I input before the current cursor

I input at the beginning of the current row

O add a row under the current row and Input

O add a row above the current row and Input

After the input is complete, Press Esc to exit the input mode.

 

3.2 move cursor

H: move one character to the left

L move one character to the right

J. Move one character down

K moves one character up

B shifts one word to the beginning of the word.

W shift one word to the end of the word

0 move to the beginning of the current row

$ Move to the end of the current row

+ Move to the beginning of the next row

-Move to the beginning of the previous row

H move to the first line of the window

M moves to the middle row of the window

L move to the last row of the window

G move to the last line of the file

NG is moved to line n of the document.

N + move n rows down

N-move n rows up

3.3 Windows Mobile

<Ctrl> + f

<Ctrl> + B windows, Volume One page

<Ctrl> + d windows half page

<Ctrl> + u windows

<Ctrl> + e windows to roll down a row

<Ctrl> + y

3.4 delete operation

X Delete the cursor character

X Delete the first field of the cursor

Dw deletes a word backward from the current position of the cursor

Db deletes a word forward from the current position of the cursor

D0 is deleted from the beginning of the row to the current cursor position

D $ Delete the cursor from the current position to the end of the row

Dd deletes the row where the cursor is located.

D is the same as d $

3.5 modify operation

Yy copy a row to the clipboard

P paste the characters in the clipboard to the current row.

S: Modify the character of the cursor. Press Esc to finish the modification.

S. Modify the entire line. Press Esc to complete the modification.

R replaces the character of the current cursor

R enters the replacement status until the end of pressing Esc

Cw modifies a word (from the cursor position to the end of the word)

Cb modifies a word (from the beginning of the word to the cursor position)

Cc modifies the entire line of content, and then press Esc to end, the same as S

C0 modifies the content from the beginning of a row to the cursor position

C $ modify the content from the cursor position to the end of the row

~ Switch the case sensitivity of the cursor's character

3.6 duplicate commands

In command mode, you can add a number n before the command, and the command will be executed n times again. Common repeated operations include:

Nx Delete n characters

Ndd Delete n rows

Ns modify n characters

3.7 cancel the previous action (Undo)

U undo the result of the previous command

3.8 search for strings

/Search for the string from the current cursor.

? The string looks forward from the current cursor to this string.

N search for the Next string from the current cursor

N search for the Next string from the current cursor

3.9 view editing status

<Ctrl> + g: displays the file name being edited, the number of lines in the current cursor, the total number of lines in the file, and whether the file is modified.

 

4. Save and exit

: W: save, but do not exit

: Wq save and exit

: X same as: wq

: Q: exit. If the current file is not saved, exit is prohibited.

: Q! Do not save and exit

: W file1 saves the content to file file1. note: the edited content is still the original file.

: W! File1 overwrites the content and saves it to the file file1. If the file file1 exists, w file1 will not be executed.

 

5. Environment Settings

: Set: displays the environment conditions that have been set.

: Set all show all environment setting options

: Set nu display row number

: Set nonu does not display row numbers

: Set ts = n set the length of the Tab key to n

Six execution commands

The following uses a specific number as an example to describe the number of rows. The row where the cursor is located can be replaced by ".", and the last row of the file can be replaced by "$.

: 10, 20 d Delete contents of rows 10th to 20th

: Delete 10th rows of content within 10 days

: % D delete all content

: 10, 20co30: copy the content from 10th rows to 20th rows after 30th rows

: 10, 20mo30 move the content from 10th rows to 20th rows after 30th rows

: 1, $ s/old/new replace the old from row 1st to the last row with the new

: 1, $ s/^/new Insert new before the content of row 1st to the last line

: 10 move the cursor to 10th rows

Seven repeated commands

. Repeat the previous command

 

Switch to shell status

: Sh switch to shell status, exit and return

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.