Handy text editing tools with Vim and EMASC, Emacs is recognized as one of the most popular code editors for professional programmers, and if only for editing text, it is recommended that vim
Vim command
/path/ text file name +num opens a file and jumps directly to Num line -b Opens the file in binary mode for editing the binary file -R Open a file as read-only
VI has three modes of operation
1. |
Command-line mode |
Command line |
2. |
Input mode |
Input mode |
3. |
Last-line mode |
Last line mode |
Command line mainly does the job of replacing, deleting, copying and so on.
Input mode mainly edits the content.
Last line mode mainly edits the file, such as saving the file
Move the cursor up or down
G (shift+ g) move directly to the end of the file GG moves directly to the file header if you want to move to a specified line, vi can also do this, assuming that the cursor is currently500line 1000G moves down to1000line 50gg moves up to50Line0 (number keys) move directly to the wardrobe $ move directly to the end of the line word move W moves directly to the next word B moves directly to the previous word PageUp down one page pag Edown up one page H move the cursor to the top M of the current screen move the cursor to the middle of the current screen L move the cursor to the top of the current screen, and place the cursor in the middle of the screen X to remove the cursor . Position of the character D from the beginning of the cursor to the end of the line all delete dd Delete cursor on the line of the DW delete cursor after a word DB delete cursor in the previous Word DG delete the cursor line to the end of the file all content DGG delete the cursor row All content to the header of the file 4x after deleting the cursor 4 characters (including the cursor)u undo the action you just made, you can use U to undo all the actions in a row in a row Ctrl + R cancels the contents of the Undo Ctrl+ G Displays information about the currently edited file
Y copy, such as yw copy a word
YY Copy a row
P paste (after cursor)
(Cuts need to be deleted and then pasted directly to the specified location)
the V key is used to select, V to select the entire row , ^v to select the entire column
Insert:
A: Start inserting after cursor: start inserting O (uppercase) before the cursor: Start inserting a new blank line at the bottom of the cursor O (lowercase): Insert a row at the beginning of the cursor
Vim search directly by/+ characters (can be matched with regular expressions) cancel search results with Noh
Last-line mode:
: w Save file: Q exit VI edit: q! Force exit
: w! Force Save: Wq Save the file and exit the VI editor (whether or not you modified the file ): E<filename-new> stores the currently edited file into a new file: x The file is written and exited only if it is modified, and exits without writing
To jump to a specified row, enter the specified number of lines directly in the last row mode
Save N1 line to N2 row input : n1, n2w/directory/filename to save
If you want to read the contents of another file in a row in the currently edited file
: 23r/home/last.txt starts reading the Last.txt file in the/home directory in line 23 of the current file
vi can open multiple files simultaneously command VI file 1 file 2 File 3 file 4
: Next switches to the next file
: Last switch to final file
: First switches to the last file
: Next switches to the next two files
: args can display files that are currently being edited in multiple edit files
: Args has another function that is to reorder the open multiple files, and the arrangement method is simple, in the last-line mode execution
: args 5 3 1 2 4 6
So the order of the original 1 2 3 4 5 6 file becomes 5 3 1 2 4 6
Split screen in VI
: Split divides the screen into multiple windows Ctrl+w + or- to resize the window Ctrl+W arrow keys to switch windows: Close Close the window where the cursor is located: Edit to open a file in a window: help view the assistance document
Find command s in VI
g Replace all found content C each time the replacement is manually confirmed that Y agree N still continue to replace, Q exit Replace I ignore case I do not ignore case e does not show error message example: This is:% s/This/that/ g/usr/bin directory Replacement/home:% s/\/usr\/bin/\/home/g Add a word at the beginning of each line Linux:% s/^/linux/ G Add a S to each word:% s/$*\>/s/g
: Suspend VI temporarily put the rest in the background. Recovery with FG (^Z)
Defining shortcut keys in vim
Definition Format: Map f2-f4 Execute command
Use the method to execute in VIM
: Map <F2> DD define the F2 function key as DD
Role
Exit the last line mode and try F2 in command mode
Note: The shortcut keys defined here will expire after you exit vim.
The command to compare files on the command line is Vimdiff:
$vimdiff File_c file_a
The following actions are performed for file comparisons in VI:
$vi file_a File_c
:d iffsplit file_a~:
// Show line numbers when opening a file // Ignore case when looking for string // indent each width by 2 when using the TAB key // Turn on color support
Linux Editor God--vim