Linux how to use vi /vim command

  

vi is a text editor, and vim is a text editor similar to vi, is a practical tool for code editing, the following small series will introduce you how to use Vi, Vim Order, interested friends to come and understand.

First, the general pattern: delete, copy, and paste commands of

x, X x to delete a character backward, X is a previously deleted character

Nx (n for numbers) Delete n characters backwards

dd Delete current line

D Delete all characters in the current line, try to become blank lines

ndd(n stands for numbers Delete the down n column of the line where the cursor is located

d1G Delete all data from the line where the cursor is located to the first line

dG Delete all data from the line of the cursor to the last line

yy Copy the line where the cursor is located

y1G Copy all the data from the cursor line to the first line

yG Copy all the data from the cursor line to the last line

ynj(n Represents the number) Copy the cursor line down n+1 line

dnj (n stands for number) Delete the cursor line down n+1 line

p,P p Paste the copied data In the next line of the cursor, P is the copied data pasted on the previous line of the cursor

J Combines the line of the cursor with the data of the next line. Line

u Resume the previous action (undo)

Second, edit mode command

i, I i is the text to insert the input at the current cursor, I is in The first non-null character of the cursor line is inserted into the input text

a, A a is the text inserted in the next character at the current cursor position, and A is the next character of the last character in the line where the cursor is located. Insert the input text

o, O o is to insert the character at the beginning of the next line of the cursor line, O is to insert the character at the beginning of the line of the line where the cursor is located

r R r is the character that replaces the cursor, R is the character that the cursor points to, until the exit

Esc exits, returns to the normal mode

3. Command mode

h The cursor moves one character to the left

j The cursor moves down one character

k The cursor moves up one character

l The cursor moves one character to the right

Ctrl+f Screen down one page

Ctrl+b Screen up one page

Ctrl+d The screen is turned down half a page

Ctrl+u The screen is turned up half a page

+ The cursor moves to the first non-empty character of the next line

- The cursor moves to the current The first non-null character of the line

n space (n represents a number) The cursor moves n characters to the right of the current line

0 (number 0) The cursor moves to the first of the current line Characters (can be null characters, note and -)

$ Cursor moves to the last character of the current line (can be a null character, note the distinction between -)

H cursor moves to The first non-null character of the line at the top of the current screen

M The first non-null character of the line moving to the middle of the current screen

L The cursor moves to the current screen. The first non-null character of the line below

G The cursor moves to the first non-null character of the last line of the article

nG(n stands for number) The cursor moves to the article The first non-null character of the n line

n The cursor moves down the current line by the first non-null character of n lines

/word Look for the word string

after the cursor? Word Find the word string before the cursor

:s/word1/word2/g Find word1 on the current line of the cursor and replace it with word2

:n1,n2s/word1/word2/g Find word1 between line n1 and line n2, and replace it with word2

:%s/word1/word2/g Find word1 for the entire article and replace it with word2

:w will edit Save the data to the hard disk file

:w [filename] Save the edited data to another file on the hard disk

:r [filename] When editing the data, read in another The data in a file, the content in the file is added to the next line of the cursor

:wq or :x Save and exit

:q Exit, for unmodified files < Br>

:q! Forced to exit, apply to modify the file without saving and exit

:set nu display line number

:set nonu cancel line number

:n1,n2 w [filename] The contents of the n1 to n2 lines are saved to a file named filename

The above is the usage of the vi and vim commands in Linux. This article briefly introduces the usage of these two commands. The specific example operation is also Please pay more attention to the system home.

Copyright © Windows knowledge All Rights Reserved