Linux command introduction: VI command application highlights

  

Enter vi command

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 on the first line of the nth line

vi + filename : Open the file and place the cursor on the last line

vi +/pattern filename: Open the file and The cursor is placed at the first string that matches pattern

vi -r filename : A system crash occurred during the last edit with vi, restoring filename vi filename....filename :Open multiple files, Edit

Move Cursor Commands in turn //This article comes from www.45it.com

h : Cursor moves one character to the left

l : Cursor moves one character to the right

space: Cursor moves one character to the right

Backspace: Cursor moves one character to the left

k or Ctrl+p: Moves the cursor up one line

j or Ctrl+n : Cursor moves down one line

Enter : Cursor moves down one line

w or W: Cursor moves one word to the beginning

b or B: Move the cursor one word to the beginning of the word

e or E: Move the cursor right one word j to the end

): The cursor moves to the end of the sentence

( : The cursor moves to the beginning of the sentence

}: The cursor moves to the beginning of the paragraph

{: The cursor moves to the end of the paragraph

nG: The cursor moves to the nth line First

n+: The cursor moves down n lines

n-: The cursor moves up n lines

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

H : The cursor moves to the top line of the screen

M : The cursor moves to the middle line of the screen

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

0: (Note that the number is zero) Cursor moves to the beginning of the current line

$: Cursor moves to the end of the current line

Screen rollover command

Ctrl+u: Half-screen to the first page

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

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

Ctrl+b; flip the file to the first screen

nz: Scroll the nth line to the top of the screen and roll the current line to the top of the screen without specifying n.

Insert text class command

i : Pre-

I: At the beginning of the current line

a: After the cursor

A: At the end of the current line

o: New under the current line Open a line

O: Open a new line above the current line

r: Replace the current character

R: Replace the current character and the following characters until you press the ESC key

s: From the current cursor position, replace the specified number of characters with the input text

S: Delete the specified number of lines and replace them with the input text

ncw or nCW: modify the specified number of words

nCC: modify the specified number of lines

delete command

ndw or ndW: delete the start of the cursor and the following n -1 word

do: delete to the beginning of the line

d$: delete to the end of the line

ndd: delete the current line and the next n-1 line

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

Ctrl+u: deletes the text entered in the input mode

Search and replace Command:

/pattern: from the beginning of the cursor to the end of the file Pattern pattern ? pattern: search for the file from the beginning of the cursor to the file first: repeat the last search command in the same direction

N: repeat the last search command in the reverse direction

:s/p1 /p2/g: Replace all p1 in the current line with p2

:n1,n2s/p1/p2/g: Replace all p1 in the n1nd to n2 lines with p2

:g/p1/s//p2/g: Replace all p1 in the file with p2

Option settings

all: List all option settings

Term: Set terminal type

ignorance: ignore case in search

list: display tab stop (Ctrl+I) and end-of-line flag ($) number: display line number

report: shows the number of commands modified by line-oriented commands

terse: displays short warning messages

warn: if you do not save the current file when you transfer to another file Display NO write information

nomagic: Allow special characters in front of the search mode without "\\"

nowrapscan: Disable vi when the search reaches both ends of the file, and from another Start

mesg: Allow vi to display information written by other users to write on their own terminal

Last line mode command

:n1,n2 co n3:n1 line Copying content between lines n2 to line n3

:n1,n2 m n3: Move the contents between lines n1 to n2 to the line n3

: N1, n2 d : Delete the contents between n1 lines and n2 lines

:w : Save the current file

:e filename: Open the file filename for editing

: x: Save the current file and exit

:q: Exit vi :q!: Do not save the file and exit vi :!command: Execute the shell command command :n1,n2 w!command:put the file n1 to The content of the n2 line is input as the command and executed. If you do not refer to

, n1, n2 means that the entire file content is used as the input of command
:r!command: command command The output is placed on the current line.

Copyright © Windows knowledge All Rights Reserved