The use of the Linux VI editor and some quick commands

Source: Internet
Author: User


The VI Editor can perform text operations such as output, delete, find, replace, and so on. VI processes the text as a command line. Open VI It occupies the entire screen.

options for the VI command and its significance

-C command Execute command before editing the file

-r filename Recovery file filename

-R editing files as read-only

+n file to edit file and place cursor on nth line

+ File to edit and place the cursor on the last line

+/string file edits the file and places the cursor in the row of the string that the first protection string represents

VI No Add file that will automatically create a new empty file.

VI Port.txt (This is a file I opened)

Family.51cto.blog.com

Edul

Www.baid$u.com

www.ywtou.top$

~

~

~ (tilde fills an unfilled line)

~

~

~

~

~

~

"Port.txt" 4L, 57C (last line shows file name, number of characters, number of bytes)

Open VI Editor There are two modes one is General mode and insert mode. There is, strictly speaking, an end-of-line pattern. Let's talk.

First of all: is the general mode is like above just open file Display file screen is the general mode, the general mode can only see can not modify the editor.

Family.51cto.blog.com

Edul

Www.baid$u.com

www.ywtou.top$

~

~

~ (tilde fills an unfilled line)

~

~

"Port.txt" 4L, 57C

Next: Is the last line mode, the last line mode is the input colon can enter the last line mode as shown below

Family.51cto.blog.com

Edul

Www.baid$u.com

www.ywtou.top$

~

~

~

~

~

~

: Shown so that in the last line mode we can execute some exit save commands

vi Editor text save and Exit commands

Save and Exit command description

W Save the text of the editor

Q Leave vi text editor, without changing the text case

Q! Text has been modified, but does not want to be stored, use this command to force leave VI

Wq store text and leave the VI text editor

Finally: Insert mode is required in general mode to enter a command to enter into insert mode as shown below

Family.51cto.blog.com

Edul

Www.baid$u.com

www.ywtou.top$

~

~

~


--INSERT--

Command mode (a I o capital letter opposite a I o) into insert mode There are other commands to enter the Insert mode, we first understand these, they are more commonly used, but also enough for us to use.

Enter insert mode common commands

A the line of the cursor is inserted backwards into the last insert of the line where the cursor is located

I cursor line forward insert I cursor line to the top insert

o cursor line down insert o cursor line up

VI command for moving the cursor

Command Action

H Move the cursor to the left

J + Enter Move Down

K-Up Move

L Move Right

Move the cursor to the end of the current paragraph

{ the beginning of the current paragraph

) at the end of the current sentence

( The beginning of the current sentence

^ The first non-null character of the current line

$ Current Line End

: N moves to row n

Common VI Editing commands

Command Action

X Delete the character at the cursor's current position

DD Delete the entire line of text where the cursor is located

d$ Delete the current cursor position to the end of the line all text D: Delete the current letter after

DW deletes words forward from the current cursor position

J Merge the next line of text content to the end of the bank

W: one word moves backwards B: one word moves forward

End: Current Line end home: The beginning of the current line

G: Text cat first line 10GG: Move to the 10 line position after the cursor

H: Current screen head M: Current screen middle L: current screen End

G: Last line of File

Y W paste a Word

YY: Copy a row can be added number 5YY cursor current after 5 lines contain

U: Undo Once

U: Undo All

D W: Delete a word

D d: Delete Row 10dd: Delete 10 rows

D: Delete the current letter after D ^ Delete the current letter before

Search: VI Editor's search function, enter "/" below the VI editor, search for string to be entered

Replace: The basic format of the Replace command for the VI editor is:

: S/old_string/new_string replaces the first occurrence of old_string with new_string

: S/old_string/new_string/g will replace the full text with old_string new_string

VI Editor Search and replace commands

/word searches for a string named WORD from the current cursor position

Word from the current cursor position search up the string named Word

: n1,n2s/word/word2/g word N1 line to N2 line is replaced by Word2

: 1, $s/word1/word2/g 1th to the last line word1 all replaced by Word2

Input in last-line mode: Set NU automatic arranging Nonu delete

Change symbol 10,15s/--/$/g will--replace with $%s/$/¥/g

3,9s/^/$/g Add 3 to 9 lines at the beginning plus $


This article is from the "Family" blog, make sure to keep this source http://family.blog.51cto.com/11742285/1957552

The use of the Linux VI editor and some quick 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.