vi editor related commands

1. The vi editor has three modes:
   general mode (press ESC to enter)
   editing mode (in general mode, type i, I, o, O, a, A, r, R)
   command line command mode (in general mode, type ':', / ,?)


2, general mode: the lower left corner will display the status of the file: name, number of lines and characters or [New File]
 
move the cursor
h,j,k,l Left, down, up, right, move one character, lowercase L, 30k move up 30 lines, not enough to reach the first line
ctrl+f/b one page down, one page up
ctrl+d/u half page down, half page up
+      - The beginning of the next or previous line of a non-space character
number + space Move the cursor backward by the corresponding number of characters
Number 0 $ start of line, end of line
H M L Move to the first line of the current screen, Chinese and English, the first character of the last line
G    move to the last line of this file
number n+G Move to the n lines of the file, and move to the last line of the file after the number of lines exceeds
gg     Move to the first line of the document, equivalent to 1G
Number n+carriage return move down n lines (a space is a backward move character)
Text Editor
x, X, nx, nX Backward, forward delete one character, or n characters
dd, ndd, dnG, dG Delete the line where the cursor is located, (including the line where the cursor is located) down n lines, to the nth line, the last line
d$,d0
yy, nyy, ynG, yG Copy the line where the cursor is located, n lines down, (same as dd)
p,P p is pasted to the next line of the cursor, P is pasted to the previous line of the cursor
J The line where the cursor is located and the next line are combined into one line and separated by a space (with and only one space)
ncj Delete n lines down and enter edit mode, rewrite the current line (the current line has no data)
u,ctrl+r,decimal point Restore the previous operation, redo the previous operation, '.' is to repeat the previous action



2. Command line command mode (in general mode, type ':',/,?)
  
Type / or ? to enter the string to search for search down or up
n,N Repeat the previous search action, reverse the previous search action
n1、n2s/word1/word2/g Replace the word1 string word1 between lines n1 and n2 with the string word2
1、$s/word1/word2/gc From the first line to the last line, replace, you need to confirm before replacing
:w,:w!,:q,:q! save, leave
n1 n2 w[filename]

3. Copy and paste (in command mode) to
   copy the entire line, the cursor is at the current line, type yy
   to copy the word, the cursor is at the first letter of the current word, type yw
   paste, type p

4, undo (command mode)
   type u

5, jump (command mode),
   type 150gg to jump to line 150

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327007678&siteId=291194637