编程知识 cdmana.com

Linux learning notes (4) VI editor

vi (Visual Interface) It's all *nux System under the standard text editor , amount to Windows Notepad in the system

It has three modes , Command mode (Command Mode)、 End of line mode (LastLine Mode)、 Edit mode (Insert Mode)

Command mode is the default mode when you open the editor , Edit mode is often used to edit text , End of line mode is often used to execute commands , Let's go through each of these


1、 Command mode

Regardless of the current mode , Press Esc Key to switch to Command Mode

(1) Move

operation describe
j / Under the direction key Move one character down
k / On the arrow keys Move one character up
h / Direction key left Move one character to the left
l / Direction key right Move one character to the right
0 Move to the beginning of the line
$ Move to the end of the line
Numbers + g Move to the specified number of rows
{ Scroll up a paragraph
} Scroll down one paragraph
ctrl + y Scroll up a line
ctrl + e Scroll down one line
ctrl + u Scroll up half the screen
ctrl + d Scroll down half the screen
ctrl + b Scroll up one screen
ctrl + f Scroll down one screen

(2) Copy and paste

operation describe
( Numbers + ) y + w Copy the specified number of words , If you don't specify a number , The default is 1 word
( Numbers + ) y + y Copy the specified number of lines , If you don't specify a number , The default is 1 That's ok
p Paste to the character or line of the current cursor
P Paste to the character or line of the current cursor

(3) Delete and revoke

operation describe
d + d Deletes the line where the cursor is located
Numbers + d + On the arrow keys / Under the direction key Delete the specified number of rows in the specified direction starting from the cursor
Numbers + x Delete the position of the cursor and the characters specified after it
Numbers + X Delete the cursor position and the characters specified before it
u revoke

2、 End of line mode

When in Command Mode Next , Press : You can switch to LastLine Mode

(1) Open and close

operation describe
e + file New file
n + file Open file
w Save the contents of the current file
q Exit file editing
wq After saving the file, exit file editing
qa Exit all file editing
q! Force exit from file editing , Do not save

(2) Find and replace

operation describe
? character string Looking forward from the current position for a specific string ( Press n Find the next one , Press N Find the last one )
/ character string Find a specific string backwards from the current position ( Press n Find the next one , Press N Find the last one )
g Global replacement

(3) Edit settings

operation describe
set n / set nonu According to the line Numbers / Cancel the display line number
set ai / set noai Automatic indentation / Cancel auto indent
syntax on / syntax off Syntax highlighting / Remove syntax highlight

(4) Working with multiple files

operation describe
prev Switch to previous file
next Switch to next file
first Switch to the first file
last Switch to the last file

3、 Edit mode

When in Command Mode Next , Press i / I / a / A / o / O Can switch to Insert Mode

  • i: In front of the character where the current cursor is , Switch to input mode
  • I: At the beginning of the current cursor line , Switch to input mode
  • a: After the character of the current cursor , Switch to input mode
  • A: At the end of the current cursor line , Switch to input mode
  • o: Insert a line below the current cursor line , Switch to input mode
  • O: Insert a line above the current cursor line , Switch to input mode

This mode is mainly used to edit text

版权声明
本文为[Half rainbow]所创,转载请带上原文链接,感谢
https://cdmana.com/2021/05/20210505025032593I.html

Scroll to Top