CentOS System vi working mode and usage of common commands

Source: Internet
Author: User
Tags centos

VI Mode of work

VI has three basic working modes:

1. Command mode: Instruction mode mainly uses the arrow keys to move the cursor position to edit the text

2. Text input mode: Press a/a, i/i, o/o to enter text mode in command mode

3. End line mode: End line mode mainly for some text editing auxiliary functions, such as String search, substitution, save files and other operations

In command mode, enter a, I, O into the text entry mode (input mode)

Press ESC to enter command mode under text input mode (input mode)

Command mode input: Enter the end line mode.

End-line mode, instruction error returns instruction pattern (Command mode)

VI Command common usage

Here are the most basic of the most commonly used VI command ~ Toss VPS enough, such as the order to quit VI and so on ~

0, to enter the order of VI

VI FileName: Open or create a new 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 nth

VI FileName: Open the file and place the cursor at the top of the line

Vi/pattern FileName: Opens the file and places the cursor in the first matching string

Vi-r filename: A system crash occurred during the last edit with VI, filename restored

VI filename....filename: Open multiple files, edit in sequence

1. Command mode

Pagedn-----Move Down one page

PageUp-----Move up one page

0-----Cursor moves to the beginning of the line

H-----The cursor moves one grid to the left

L-----Move the cursor to the right one grid

J-----Move the cursor down one line

K-----Move the cursor up one line

$+a-----Move the cursor to the end of the line

d+ Arrow-----Delete Text

DD-----Delete entire row

PP-----full row copy

R-----Modify the character of the cursor

S-----Delete the column where the cursor is located and enter the input mode

2. Text Input mode

A-----begin inserting after the cursor

A-----begin inserting at the end of A line

I-----insert from the position in front of the cursor

I-----begin inserting before the first non-white-space character in the column where the cursor is located

o-----Add a new column under the cursor and enter input mode

O-----Add a column above the column where the cursor is located and enter input mode

ESC-----Return to command line mode

3. Last line mode

: Q-----End VI program, if the file has been modified, save the file first

: q! -----Force Exit VI Program (without saving changes)

: Wq-----Save changes and exit the program

ZZ-----Save the changes and exit the program (hold down the SHIFT key when CAPS LOCK is not turned on and press the two Z key)

: Set num-----Setting line numbers

Move and copy

==========

Delete and put instructions can be used to complete the data removal purposes.

The use of Yank and put instructions to complete the purpose of data replication.

Yank and delete can copy the specified data to the memory buffer, and with the put instruction

The data in the buffer can be copied to the screen.

Cases:

Move a row. Executing DD on the line

. Move cursor to destination

. Executive P

Copy a row. To execute YY on the line

. Move cursor to destination

. Executive P

. Instruction Duplication

=========

In instruction mode, you can add a number n before the instruction, and the instruction action repeats the n

Times.

Cases:

Delete 10 lines. 10DD

Copy 10 lines. 10yy

. Move cursor to destination

. P

The indicator moves down 10 lines. 10j

.. Cancel previous action (undo)

===================

That is, to recover the content before the previous instruction is executed.

U restore the results before the last instruction.

U restores all changes to the row of the cursor.

.. Search

=====

In VI you can search for a string to move the cursor to that place.

/String to search for the string after the cursor.

Find the string before the cursor.

n Go down and look for the next same string.

N go up and look for the next same string.

.. Connection of data

===========

The connection of the J sentence. Connects the row below the cursor to the rear of the row.

If a row of data is too long can be divided into two lines, as long as the cursor moved to separate points, enter the input mode

(can use a, I and other instructions) and then press "Enter" can be.

.. setting of the environment

===========

: Set Nu The line number of the data.

: Set Nonu cancel line number setting.

: Set AI automatic inner shrink.

: Set Noai cancels automatic indentation.

Automatic indentation (automatic indentation)

When you edit a file or program, you sometimes experience a situation where you need to shrink, and the ": Set AI" provides its own

The function of internal contraction is explained by the following example:

. VI Test

. (After entering the edit window)

This is the test for auto indent

"Tab" Start Indent←:set ai (automatic internal contraction)

"Tab" Data

"Tab" Data

"Tab" Data←:set noai (Cancel auto indent)

The end of auto indent.

. Note: You can delete the Tab character.

Delete from current position to end of line

d$

Copy from current position to end of line

y$ if you want to paste it into another place p is okay.

13.

:%s/old_word/new_word/g

This directive is to replace a specific string in the entire file

14. Cursor Control

K: Move up NK up N line

J: Move Down NJ down n row

Move the cursor to the nth line, and press Mk

Move the cursor to line M and press "Ay ' K"

The rows N to M are to be saved to a register, and so on, b,c ... Registers, etc.

This will allow you to paste your favorite content into a different register to spare

Want to paste somewhere, directly to move the cursor to a place, press the ' AP can, and so on, b,c ... Registers, etc.

In the current screen

H jumps to the first line

M jumps to the middle row

L jump to the last line

15.

Table 8-2 Delete Commands

Delete command action

D l deletes the current character (same as the X command function)

D 0 Delete to the beginning of a line

d ^ Delete to the first character position of a line (excluding spaces or ta b characters)

D-W deletes to the end of a word

D 3 W Delete to the end of the third word

D b Delete to the beginning of a word

D W deletes to the end of a word that is delimited by a space

D B Delete to the beginning of a word with a space separator

D 7 B Delete to the beginning of the previous 7 words with a space separator

d) Delete to the end of a statement

D 4) Delete to end of fourth statement

D (deletes to the beginning of a statement

D} deletes to the end of a paragraph

d {Delete to the beginning of a paragraph

D 7 {Delete the 7th paragraph position before the beginning of the current paragraph

D d Delete When moving forward

d/t e x t deletes the position of the typeface specified in "T e x T" from the text until the next occurrence of the typeface

The content between the location (but not the typeface)

D FC deletes the position of the character "C" appearing from the text until the next occurrence of the character (including

The content between the characters)

D TC Delete the current line until the next character "C" appears between the contents of the

D Delete to the end of a line

D $ Delete to the end of a line

5 D D deletes 5 lines of content starting from the current line

D L Delete until the last line on the screen

D H Delete until the contents of the first line on the screen

D G Delete the content until the end of the work buffer

d 1 G Delete content until the work buffer begins

Replace command

Replace command action

s replaces the current character with one or more characters

S to replace the current line with one or more characters

5 S replaces 5 characters starting with the current character with one or more characters

VI Replacement Usage rules:

: g/s1/s/s2/s3/g

The first G represents the replacement of each row that includes S1, and the second G indicates that all S2 for each row including S1 are replaced with S3

s represents substitution, S2 is the string to be replaced, he can be the same as S1 (if the same words are replaced by//), S3 is the replacement string

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.