Shell Text Manipulation commands

Source: Internet
Author: User
Tags save file

The VI editor has three status modes "VI file name (or path + file name)"

1. Command mode

2. Input mode

3. Last-line mode

Conversion between three modes

Vi. start and exit of the VI editor

Go directly to the editing environment

$ VI

Enter the editing environment and open (new) file

$ VI myfile

Exit VI Editing Environment

Enter the last line command to discard changes to the file and exit the editor

: q!

Save files as

Save File

Save changes to open files in the VI editor

: W

Save As File

Save the contents of the VI editor as a specified file name

: W myfile

There are several ways to exit the VI editor:

Exit not modified

No changes have been made to the file opened in the VI editor, or modifications have been saved, exit the VI editor directly

: Q

Save and exit

Save the file in the VI Editor and exit the VI editor

: Wq

Do not save exit

Discard changes to the contents of the file and exit the VI editor

: q!

Cursor Movement and page-flipping operations

Action type cursor action key function

H move the cursor to the left

L MOVE the cursor to the right

K Move Cursor up

J Move Cursor Down

Flip Ctrl + F to turn the whole page forward

Ctrl + B Turn back full page

Ctrl + U turn half page forward

Ctrl + D turn back half page

Quick Jump in line

Operation Key function

^ Quickly jump the cursor to the beginning of the line character

$ quickly jumps the cursor to the line end character of the bank

W quickly jumps the cursor to the first letter of the next word at the current cursor position

B quickly jumps to the first letter of the previous word at the current cursor position

E quickly jumps the cursor to the end of the last word at the current cursor position

Quick jump between documents and insiders

Command function

: Set NU Displays line numbers in the editor

: Set Nonu cancels the line number display in the editor

1G jump to the first line of the file

G Jump to the end of the file line

#G跳转到文件中的第 # Line

Enter input mode

Command function

I enter the insertion state at the current cursor

A enters the insertion state after the current cursor

A moves the cursor to the end of the current line and into the insert State

o Insert a new line below the current line, and the cursor moves to the beginning of the new line and into the insert State

o Insert a new row above the current line, and the cursor moves to the beginning of the new line and into the insert State

CW Delete the current cursor to the end of the word at the end of the character, and into the insert State

C $ Deletes the current cursor to the end of the line and enters the insert state

The c^ command deletes the characters from the beginning of the current cursor (excluding the characters on the cursor) and into the insertion state

Edit key operation for input mode

Key function

Arrow key to move the cursor around the left and right direction

Home Quick position cursor to beginning of line

End quick position cursor to end of line

PageUp to page up the text

PageDown to page down the text

BACKSPACE delete the character to the left of the cursor

Del Delete character at cursor position

Delete operation

Command function

x Delete a single character at the cursor

DD deletes the cursor in the row

DW deletes all characters from the current character to the end of the word (including spaces)

De removes all characters from the current character to the end of the word (excluding spaces at the tail of the word)

d$ Delete all characters from the current character to the end of the line

d^ Delete all characters from the current character to the beginning of the line

J Delete line breaks at the end of the line at which the cursor is located, equivalent to merging the contents of the current and the next line

Undo Action

Command function

U cancels the last operation and restores the result of the operation

You can use the U command multiple times to recover a multi-step operation

U cancels all operations on the current line

Ctrl + R Restores operations that use the U command to undo

Copy and paste operations

Command function

YY copies the contents of the entire row of the current line to the VI buffer

YW Copy the contents of the current cursor to the end of the word to the VI buffer

y$ Copy the contents of the current cursor to the end of the line to the VI buffer

y^ Copy the contents of the current cursor to the beginning of the line to the VI buffer

P reads the contents of the vi buffer and pastes it to the current position of the cursor (without overwriting the contents of the file)

String Lookup Operations

Command function

/word from top to bottom in file find string "word"

Word bottom finds the string "word" in a file

N locates the next matching found string

N locates the previous matched lookup string

String substitution operations

Command function

: S/old/new replaces the first character "old" string found in the current row with "new"

: S/old/new/g replaces all the string "old" found in the current row with "new"

: #, #s/old/new/g Replace all strings "old" with "new" in the line number "#,#" range

:%s/old/new/g replaces all strings "old" with "new" in the entire file range

: s/old/new/c the C command at the end of the Replace command, prompting the user to confirm each substitution action

VI Editor's online Help

Packages to be installed using VI online Help

vim-common-6.3.035-3.i386.rpm

vim-enhanced-6.3.035-3.i386.rpm

Package 2nd installation CD in RHEL5

Two ways to use VI online Help

Press the "F1" key in the VI editor

Enter the help last line command

Shell Text Manipulation commands

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.