Linux operating system using the vi editor, Detailed
Enterprise
2019-08-16 22:39:46
views: null
Introduction to the vi editor
- vi editor is the most basic Linux and Unix text editor, working in text mode. Since no graphical interface, vi is a highly efficient text editor. Although there are many graphical editors available on Linux, but vi and server management functions in the system are those graphics editor can not match.
- vi is not a layout editor program, it is not WPS as Word or other attributes may be organized fonts, formatting, paragraphs, etc., it is only a text editing program. No menu, only the command, and command range. vi There are three basic modes: command-line mode, text input mode and line mode.
- Vi enhanced version of Vim is easier to use than vi. vi commands can be used in almost all the vim.
The role of the text editor
Linux is the most commonly used text editor
Operating modes vi editor
Three operating modes
mode |
effect |
Command Mode |
In this mode, the user can input various legal Vi command to manage their documents. |
Input Mode |
In this mode, any character entered by the user are saved vi as the contents of the file, and displays it on the screen. |
Line mode |
Most file management commands are executed in this mode, the last line command after the implementation, Vi automatically return to command mode. |
Switching between different modes
hot key |
effect |
hot key |
effect |
a |
Is inserted before the cursor |
i |
Inserted after the cursor |
O |
The next line where the cursor is inserted |
O |
Insert the cursor line |
: |
Line mode |
Esc |
Exit the current mode and return to command mode |
Basic operation command mode
Move the cursor
Action Type |
Operation keys |
Features |
Direction |
↑、↓、←、→ |
up down left right |
Next page |
Page Down或Ctrl+F |
Scroll down the entire page content |
|
Page Up或Ctrl+B |
Flip up the whole page content |
Quick Jump in the line |
Home key or "^", the number "0" |
Jump to the beginning of the line |
|
End key or "$" button |
Jump to the end of the line |
Quick jump between the lines |
1G or gg |
Jump to the first line of the file |
|
G |
Jump to the end of the line in the file |
|
#G |
Jump to file the first line # |
Display line numbers |
: Not set |
Line numbers displayed in the editor |
|
:set nonu |
The line number is displayed to cancel the editor |
Copy, paste, delete
Action Type |
Operation keys |
Features |
delete |
x or Del |
To delete a single character at the cursor |
|
dd |
Delete the current cursor row |
|
#dd |
# Delete the contents of the line starting from the cursor line |
|
d^ |
Delete all the characters before the current cursor to the beginning of the line |
|
d$ |
Delete all the characters in the current cursor to the end of the line |
|
dw |
Delete the word at the cursor location |
copy |
yy |
Copy the contents of the entire line of the current line to the clipboard |
|
#yy |
# Copy the contents of the line starting from the cursor line |
Stick |
p |
After the contents of the buffer is pasted to the cursor position |
|
P |
Before pasting the cursor position |
Find the file contents
Operation keys |
Features |
/word |
Find a string from the top down "word" in the file |
?word |
From the bottom up search string "word" in the file |
n |
Locating a next matching search string |
N |
Positioning a matching search string |
Undo edit and save and exit
Operation keys |
Features |
in |
Press once to cancel the last operation, repeat u key to restore multiple operations |
The |
To cancel all edits to the current row than done |
ZZ |
Save the current file and exit the vi editor |
The basic operation of the line mode
Save the file and exit the vi editor
Features |
command |
Remark |
save document |
:w |
Save the modified contents |
|
:w /root/newfile |
Save as another file |
Exit vi |
:q |
Unmodified exit |
|
:q! |
Abandon contents of the file and exit vi |
Save the file and exit |
:wq |
Save the modified contents and exit |
Open a new file or read other file content
command |
Features |
:e /install.log |
Open a new file for editing |
:r /etc/filesystems |
Read other file contents in the current document I |
Replace the contents of the file
command |
Features |
:s/old/new |
The current row find the first character in "old" string is replaced with "new" |
:s/old/new/g |
The current row to find all the strings "old" is replaced with "new" |
:#,# s/old/new/g |
Replace all strings "old" the row number "#," the range "new" |
:s/old/new/c |
In the Replace command to join the end of the c command. Each action will prompt the user for confirmation to replace |
Vi editor keyboard comes bitmap
Origin blog.51cto.com/14473285/2430179