VI Editor Common commands

Source: Internet
Author: User

VI Editor can be divided into 3 states, they are command mode, input mode and the last line mode, vi run after the default into the command mode.

Command mode: Controls the movement of the screen cursor, the deletion and substitution of characters, words or lines, the copying and pasting of data, and the insertion and end-of-line modes.

Input mode: In command mode, the characters entered by the user will be interpreted by VI as the command interpretation execution. If the user takes the input character as text, it must first enter the input mode. You can enter input mode by pressing the A,I,O key in command mode. Press the ESC key in input mode to return to command mode.

Last-line mode: In command mode, press the ":" Key to enter the final row mode, at which time VI displays a ":" Prompt at the end of the display window, where the user can enter commands. Under this file, you can save the file, Exit VI, find and replace characters, list line numbers, jump to lines that specify line numbers, and so on. Command mode is returned automatically when the command is completed, and can be returned manually by pressing the ESC key.

Several ways to enter the input mode

I: Inserts the text before the current cursor is positioned.

I: Move the cursor to the beginning of the current line and insert text before the beginning of the row.

A: Inserts text after the current cursor is in place.

A: Move the cursor to the last row of the current line and insert the text after the last line.

o: Insert a new line below the line where the cursor is located, and move the cursor to the beginning of the new line to insert the text.

O: Insert a new row above the line where the cursor is located, and move the cursor to the beginning of the new line to insert the text.

Command-line mode

0 or ^: Moves the cursor to the beginning of the current line.

$: Moves the cursor to the end of the current line.

DD: Deletes the line where the cursor is located.

Do: Delete to the beginning of the line

d$: Delete to end of line

U Undo Last Modification

U Undo all modifications to the current line

. Repeat last Modification

Search string using/or?,/means search down,? Indicates search down

For example, to search for "bind-address" from the start, you can use/bind-address and then press ENTER, N is the lookup for the next, N finds the previous, and if the search contains special characters you can use the transfer symbol "\"

Replace string

: s/str1/str2/#用字符串str2换行中首次出现的字符串str1

: s/str1/str2/g #用字符串str2替换行中所有出现的字符串str1

:., $ s/str1/str2/g Replace all occurrences of the current line to the end of the string with the string str2 str1

: 1,$ s/str1/str2/g replaces all occurrences of strings in the body with a string str2 str1

: g/str1/s//str2/g function Ibid. from the above substitution command, you can see that the G is placed at the end of the command to replace each occurrence of the search string, without g, which means that only the first occurrence of the search string is replaced; G at the beginning of the command, Represents a substitution operation on all rows in the body that contain a search string.

Copy the current line using YY

Paste the copied row p

Last-line mode command

W: Saves the current file.

w!: Force save.

Q: Exit VI.

q!: Do not save file Exit VI.

N: Moves the cursor to the nth row.

CTRL + G to know the line number of the cursor line

Shift+g can go to the last line

Last-line mode input: Set Nu to display line numbers

Enter line numbers directly in the last line mode to position the cursor to the specified line

After SSH enters terminal (terminal)

Ctrl+e move the cursor to the end

CTRL + A moves the cursor to the first

Ctrl+k Delete all content from here to the end

Ctrl+u Delete here to start all content

Ctrl-l Clear the current screen

Ctrl-c-Kill the current task

Copy as Ctrl-shift-c

Paste as Ctrl-shift-v

tab= Full complement

VI Editor Common commands

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.