Simple introduction to multiple Linux VI commands

Source: Internet
Author: User

The following describes the Linux VI commands of Ubuntu., Linux VI commandThe usage method is helpful to everyone. Improve the Linux technology.

Go to vi command

Vi filename: open or create a file and place the cursor at the beginning of the first line

Vi + n filename: open the file and place the cursor at the beginning of line n

Vi + filename: open the file and place the cursor at the beginning of the last line

Vi +/pattern filename: open the file and place the cursor at the first string matching pattern

Vi-r filename: the system crashed when vi was being edited last time. Restore filename vi filename... filename: open multiple files and edit them in sequence

Move cursor command

H: move the cursor one character to the left

L: move the cursor one character to the right

Space: move the cursor one character to the right

Backspace: move the cursor one character to the left

K or Ctrl + p: move the cursor up a row

J or Ctrl + n: move the cursor down a row

Enter: move the cursor down a row

W or W: move one word to the beginning of the word to the right of the cursor.

B or B: move one word left to the beginning of the word

E or E: move the cursor right to the end of a word j.

): Move the cursor to the end of the sentence.

(: Move the cursor to the beginning of the sentence.

}: Move the cursor to the beginning of the paragraph

{: Move the cursor to the end of the paragraph

NG: move the cursor to the beginning of line n

N +: move the cursor down n rows

N-: Move n rows above the cursor

N $: move the cursor to the end of line n

H: move the cursor to the top line of the screen

M: move the cursor to the middle line of the screen

L: move the cursor to the last line of the screen

0: Note that the number is zero.) move the cursor to the beginning of the current row.

$: Move the cursor to the end of the current row

Move cursor command

Ctrl + u: half screen at the beginning of the file

Ctrl + d: Flip the half screen to the end of the file

Ctrl + f: Flip the screen to the end of the file

Ctrl + B; open a screen at the beginning of the file

Nz: Rolls row n to the top of the screen. If n is not specified, the current row is rolled to the top of the screen.

Insert text commands

I: Before the cursor

I: at the beginning of the current row

A: After the cursor

A: At the end of the current row

O: open a new row under the current row

O: open a new row above the current row.

R: Replace the current character

R: Replace the current and subsequent characters until you Press ESC.

S: Starting from the current cursor position, replace the specified number of characters with the input text

S: delete a specified number of rows and replace them with the input text

Ncw or nCW: modify a specified number of characters

NCC: modifies a specified number of rows.

DELETE command

Ndw or ndW: n-1 characters starting at and following the cursor

Do: Delete to the beginning of a row

D $: Delete to the end of the row

Ndd: Delete the current row and the next n-1 row

X or X: delete a character. x deletes the character after the cursor, and X deletes the character before the cursor.

Ctrl + u: delete text entered in input mode

Search and replace commands:

/Pattern: Search for pattern from the beginning of the cursor to the end of the file? Pattern: Search for pattern n from the beginning of the cursor: Repeat the previous search command in the same direction.

N: Repeat the previous search command in the reverse direction.

: S/p1/p2/g: replace all p1 in the current row with p2.

: N1, n2s/p1/p2/g: replace all p1 from line n1 to line n2 with p2.

: G/p1/s // p2/g: replace all p1 files with p2.

Option settings

All: lists all options.

Term: Set the terminal type

Ignorance: Case Insensitive in search

List: display the tab (Ctrl + I) and the end of the line sign $) number: display the row number

Report: displays the number of changes made by line-oriented commands.

Terse: displays brief warning information

Warn: NO write information is displayed if the current file is not saved when it is transferred to another file.

Nomagic: allows you to use special characters without "\" in search mode.

Nowrapscan: Prohibit vi from searching at both ends of the file and starting from the other end.

Mesg: Allows vi to display the information that other users write to their terminal using write.

Last-line command

: N1, n2 co n3: copy the content from line n1 to line n2 to line n3.

: N1, n2 m n3: Move the content from line n1 to line n2 to line n3

: N1, n2 d: Delete content from line n1 to line n2

: W: Save the current file

: E filename: open the file filename and edit it.

: X: Save the current file and exit.

: Q: Exit vi: q! : Do not save the file and exit vi :! Command: execute shell command: n1, n2 w! Command: The content from line n1 to line n2 in the file is used as the command input and executed.

If n1, n2 is specified, the entire file content is used as the command input.

: R! Command: place the output result of the command to the current line.

Multiple Linux VI commandsI hope it will be helpful to you.

  1. The Ubuntu IT industry is still vulnerable to piracy
  2. Ubuntu openSUSE features and package Building Services
  3. How to boot the Ubuntu file from the hard disk to DOS
  4. Are you ready to enter Enterprise Server Ubuntu?
  5. The core image file of the Ubuntu installation system points to the downloaded file.

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.