Vi/vim command Explanation

Source: Internet
Author: User
Tags first string






Basic Command Learning Directory Home






Original link: https://www.cnblogs.com/mondol/p/vi-examples.html


Enter VI


vi filename# Open or create a new file and place the cursor at the beginning of the first

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 beginning of the last line

vi +/pattern filename# Open the file and place the cursor at the first string matching the pattern

vi -r filename# The last time you were editing with VI, a system crash occurred, restoring filename

vi filename....filename# Open multiple files and edit them sequentially


Save exit


w# Save current file

w /tmp1# Save As/tmp1

20,59w /tmp1# Save only 20-59 rows of memory as/TMP1

xorwq# Save exit

q# Exit VI

q!# Exit does not save

!command# Execute Shell command

n1,n2 w !command# The contents of the N1 line to the N2 line in the file are entered and executed as command, and if N1,N2 is not specified, the entire file content is entered as the command

r !command# put the command's output to the current line

w !sudo tee %# When you save without permission, you can get permission to save


Cursor movement


h# move the cursor left one character

l# move the cursor right one character

space# move the cursor right one character

Backspace# move the cursor left one character

kOrCtrl+p# cursor moves up one line

jOrCtrl+n# cursor moves down one line

Enter# move the cursor down one line

wOrW# The cursor moves right one word to the beginning of the word

bOrB# The cursor moves left one word to the beginning of the word

eOrE# The cursor moves right one word to the end of the word

)# The cursor moves to the end of the sentence

(# cursor moves to the beginning of the sentence

}# The cursor moves to the beginning of the paragraph

{# cursor moves to end of paragraph

nG# cursor moves to the beginning of nth

n+# The cursor moves down n rows

n-# move the cursor up n rows

n$# The cursor moves to the end of the nth line

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

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

L# The cursor moves to the last line of the screen

0# (Note is the number 0) the cursor moves to the beginning of the current

$# cursor moves to the end of the current line


Screen Tumbling


Ctrl+u# Turn half screen to the top of the file

Ctrl+d# Half-screen to the end of the file

Ctrl+f# Flip a screen to the end of the file

Ctrl+b# Flip One screen to the top of the file

nz# Roll the nth row to the top of the screen, and roll the current line to the top of the screen when n is not specified


Insert


i# before the cursor

I# at the beginning of the current

a# after the cursor

A# at the end of the current line

o# new row below the current line

O# new row above the current line

r# Replace the current character

R# replaces the current character and its characters until the ESC key is pressed

s# replaces the specified number of characters with the text entered, starting at the current cursor position

S# Delete the specified number of rows and replace them with the text you enter

ncwornCW# Modify the specified number of words

nCC# Modify a specified number of rows


Delete


ndworndW# Delete the n-1 word at the beginning and after the cursor

do# Delete to the beginning of the line

d$# Delete to end of line

ndd# Delete the current line and its subsequent n-1 lines

xorX# Delete a character, x after deleting the cursor, and x before deleting the cursor

Ctrl+u# Delete the text entered in the input mode

n1,n2 d# Delete the contents of N1 rows to N2 rows

%d# Delete all content

1,$d# Delete all content


Copy paste, cut, move


yy# Copy when moving forward

nyy# copy n rows at the beginning of the current line

Pressvand then the arrow key to select the region, press theycopy selection row

dd# Cut When you move forward

p(小)# Paste the content below the current cursor.

P(大)# paste content at the current cursor

n1,n2 co n3# Copy the contents of N1 line to N2 line to line N3

n1,n2 m n3# Move the contents of the N1 line to the N2 line down to line N3


Search (Find)


/abc# Search for ABC from the beginning of the cursor at the end of the file

?abc# Search for ABC from the beginning of the cursor at the top of the file

/\/abc# Search/ABC from the beginning of the cursor at the end of the file, where/is escaped

n# Repeat the last search command in the same direction

N# Repeat the last search command in the opposite direction


Replace


s/vivian/sky/# Replace the current line the first Vivian is sky

s/vivian/sky/g# Replace the current line all Vivian for Sky

n,$s/vivian/sky/# Replace the nth line start to the last row in the first Vivian of each row is sky

n,$s/vivian/sky/g# Replace the nth line start to the last row in each row all Vivian are sky

%s/vivian/sky/g# (equivalent to g/vivian/s//sky/) replaces every Vivian in each row as Sky

s#vivian/#sky/## Replace the current line the first vivian/is sky/(you can use the #或 + as the delimiter, which appears in the middle/not as a delimiter)

s/p1/p2/g# Replace all P1 in the current row with P2

n1,n2s/p1/p2/g# Replace all P1 in line N1 to N2 with P2

g/p1/s//p2/g# Replace all P1 in the file with P2


Register


"?nyy# Save the contents of the current row and its next n rows to the register? , where? is a letter, n is a number

"?nyw# Save the current row and its next n characters to the register? , where? is a letter, n is a number

"?nyl# Saves the current row and its next n characters to a register? , where? is a letter, n is a number

"?p# Remove Registers? and place it at the cursor position. Over here? Can be a letter, or it can be a number

ndd# deletes the current line and its total n lines of text, and places the deleted content in the 1th delete register.


Option settings


set number# Show Line Numbers

set number!# No Line numbers are displayed, other options are added equally! No.

set all# List all option settings

set term# set Terminal type

set ignorance# Ignore case in Search

set list# Display tab stop (CTRL+I) and Line end flag ($)

set report# shows the number modified by the line-oriented command

set terse# Displays a short warning message

set warn# Displays no write information if the current file is not saved when you go to another file

set nomagic# allows the use of special characters that are not preceded by "" In search mode

set nowrapscan# Prohibit VI when the search reaches both ends of the file and starts at the other end

set mesg# Allow VI to display the information that other users write to their terminal using write






Vi/vim Command Detailed


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.