1, the Role of text editor
Edit and modify files that exist as text in the system (especially for various profiles) and can also be used to write program code
2. Common Editor under Linux
Nano, Emacs, Gedit, VIM, etc.
3, vim three mode of work
Command mode : Browse the contents of the file, move the cursor, delete, copy, paste, find
Input mode : Enter and edit content
last-line mode : string substitution, file saving, save, vim editing environment exit
4. Basic operation in command mode (1) View operation Word Jump:
W: Jump to the beginning of the next word
B: Jump to the beginning of a previous word
E: Jump to the last word ending
In-line jump:
^: jumps to the first non-null character on the current line
0: Jump to the absolute beginning of the current line
$: Jumps to the end of the line where the cursor is located
Inline Jump:
1G or GG: Navigate to the first row
G: Navigate to the last line
12G: Navigate to line 12th
: Set Nu: Display line number
: Set Nonu: Remove line number
Tip:: Line number can jump to the specified line quickly
Flip Screen:
Flip One screen forward (page DOWN or CTRL + F)
Flip one screen backwards (page p or ctrl + B)
(2) Copy, paste and delete class operation delete operation:
x: Delete a character at the cursor location
5x: Delete the cursor position and the following 5 characters
d^: Deletes the cursor position until the beginning of the line (the character holding at the cursor position)
d$: Delete cursor position until end of line (cursor position character not preserved)
DD: Delete cursor in the row
CC: Delete the cursor line and go to input mode
4DD: Delete the wide cursor line and the following total four lines
4CC: Delete the line with the cursor and the following total four lines, and go to input mode
D1G: Delete all the contents of the line to the first row of the cursor (the row where the cursor is deleted)
DG: Delete the entire contents of the line to the last row (the row where the cursor is located)
NOTE: DD and CC can also be used for cutting operations
Tips:
: line number D deletes the specified line
: Start line number, end line number d Delete the specified range of rows for example (: 1,8d)
Copy operation:
YY: The copy cursor is in the row
4YY: Copy cursor line and the following total 4 lines
Paste operation:
P (lowercase): Pastes the copied content below the line where the cursor is located
P (UPPERCASE): Pastes the copied contents to the top of the line where the cursor is located
Block selection:
V (lowercase): Select by character, place the cursor over the white selection
V (UPPERCASE): Select by line, and place the cursor over white
Ctrl + V: Block selection, can be selected according to the rectangular way
Y: Copy the anti-white part
D: Remove the anti-white section
P: Paste the copied content behind the cursor
(3) File content lookup class operations
/String to find (from top down) eg:/name find the name string for the current file
? Find it from the bottom up.
n switches to the next matching string
N switches to the previous matching string
(4) Revoke and save exit class operations
U: Undo Last edit Operation (infinite Undo, similar to CTRL + Z in Word)
Ctrl+r: Undo the last thing that was undone
. : Repeats the last action
ZZ (uppercase): Save and exit
5, the operation of the last row mode (1) file saving and exit class operation
: W Save current document
: W file name the currently edited content is saved in another new file
: Wq Save current file and exit Vim editing environment
: Q Quit VIM editing environment
: q! Force exit if not saved
: wq! Force Save exit
(2) Open and read file class operations
: E file name opens and edits a new file
: e! Discard the edited content of the current file
: R file name reads the contents of a new file to the end of the file that is currently being edited
(3) file content substitution class operation
: S/old content/new content Eg:/boy/girl The first boy in the line where the cursor is located is replaced with a girl
: s/boy/girl/g all the boy in the line where the cursor is located girl
: 5,8 s/boy/girl/g will change all the boy 5~8 line to Girl
:% S/boy/girl Replace the first boy in each line of the file with a girl
:% s/boy/girl/g Replace all the boy in the file with girl
Tips:
1. Multi-file Operation
: Files displays information for multiple files being edited
: N switches to the next document
: N switches to the previous document
: first switch to document one
: Last switch to Final Document
2. Multi-window operation
Vim-o file 1 file 2 up/down split
Vim-o file 1 file 2 split around
To split a file
Ctrl+w+s Up/Down split
Ctrl+w+v left and right split
Ctrl+w+arrow Multi-window toggle (arrow denotes arrow key)
The text editor for Linux operations