Vim Editor
Text editor, word processor
Ascii
Nano, SED
Vi:visual Interface
Vim:vi improved
Full screen editor, modal editor
The options and meanings of VIM commands
Option Comment
-C command executes the command command before editing the file -r filename recovery file filename-r filename to edit the file in read-only mode +n filename open file, and position on nth row + filename Open file, navigate to the last line +/PATTERN : Open File, Navigates to the beginning of the line that was first matched to the pattern
Vim's syntax coloring is especially important: when you edit a bash script, it is displayed in a special color, and if there is no color, we can even interpret it as a grammatical error.
Vim mode:
Edit mode (command mode) input mode last line mode
Mode conversion:
Edit--Input:
I: In front of the character of the current cursor, into the input mode, a: After the current cursor is the character of the input mode, o: The current cursor is located below the line, a new row, and into the input mode; I: At the beginning of the line where the current cursor is located, convert to input mode A: At the end of the line where the current cursor is located, convert to input mode O: At the top of the current cursor line, create a new row and switch to input mode;
Input-to-edit:
Esc
Edit-to-last line:
:
Last line--edit:
ESC, ESC
First, open the file
# vim/path/to/somefile +#: Open the file and locate it in line # +: Open the file, navigate to the last line +/pattern: Open the file, Navigates to the beginning of the line that was first matched to the pattern
Vim file if file exists then open file
New file If file does not exist
Default in edit mode
Ii. Filing and withdrawal
last-line mode save and close files
: Q exit: Wq Save and exit: Q! do not save and exit: W Save: W! --: X
: wq! Force Save exit
: QA All exits
exit in edit mode
ZZ: Save and exit
Other:
:! command to execute the outer command in VIM: W file Save as File:r file read in file
Third, move the cursor (edit mode)
Character-by- word movement:
H: Left L: Right J,+, Enter: down k,-: Upper #h: Move # characters;
move in a word unit
W: Move to the next word first e: Jumps to the ending of the current or next word B: jumps to the beginning of the current or previous word
in-line jump:
0 : Absolute Beginning ^: first non-whitespace character at the beginning of a line $: Absolute End
Inline Jump
1g=gg jump to the first line of the file
G jump to the end line of the file
#G jump to the # line of the file (Command mode)
: # Jump to the # line of the file (last line mode) in the last line mode, directly to the travel number
Four, turn the screen
PgUp up a full page of content = Ctrl + b
PgDn down a full page of content = Ctrl + Fctrl+D: Flip down half Screen ctrl+u: Flip up half screen
V. Delete a single character
X: Delete the single character at the cursor #x: Remove the total # characters from the cursor and back
VI. Delete operations
The D command is used in combination with the jump command;
X Delete single character at cursor = Del
DD deletes the cursor in the row
Delete the line that includes the line that contains the current cursor;
d^ removed from the cursor to the beginning of the line
d$ Delete from cursor to end of line
In the last row mode: Startadd,endaddd .: Represents the current line $: last line +#: Down # line
Seven, Paste command p
P: If you delete or copy to an entire line, paste to the bottom of the line where the cursor is located, if the copied or deleted content is a non-full row, paste it after the character that the cursor is in, and P: If you delete or copy the entire line, paste it above the line where the cursor is located, or if the copied or deleted content is pasted to the front of the character where the cursor is located;
Eight, copy and paste
yy copy current cursor line #yy copy current cursor down # line P paste in last line mode copy :1, 3y copy 1-3 lines
Nine, modify: First delete the content, and then converted into the input mode
C: Usage with d command
X. Replacement: R
R: Replacement mode
Xi. Edit Operations
u: Undo Previous edit Operation Continuous u command to undo previous N edits #u: Undo the most recent # edit operation Undo the last undo action: Ctrl+r
12. Repeat the previous edit operation
.
13. Visualization Mode
V: Select by character
V: Select by rectangle
14. Find
Search for strings (last-line mode)
/World down looking for world? World up Find worldn Locate the next matching string n Locate the previous matching string
XV, find and replace
Use the S command in the last-line mode
addr1,[email Protected]@[email protected] 1 , $%: Express Full text
Substitution of strings (last-line mode)
: s/old/New replaces the first character "old" string found in the current row with "new": S/old/new/g all strings found in the current row Replace "old" with "new": #, #s/old/new/g replace all strings "old" with "new" in line number "#,#": %s/old/New/gc replaces all strings "old" with "new" in the entire file range and alerts each replacement action
16. Use Vim to edit multiple files
Vim FILE1 FILE2 file3:next switch to the next file: Prev Switch to the previous file: Last switch to the final file: first switch to file one
Exit
: QA All exits
17, split screen display a file
CTRL +W, s: Split window horizontally Ctrl+W, V: Vertical splitter window Toggles cursor between windows: Ctrl+W, arrow:qa close all Windows
18. Edit multiple files in a window
Vim-o: Vertical split display
19. Save some of the contents of the current file as a different file
/path/to/somewhere
20. Populate the contents of another file in the current file
: R/path/to/somefile
21, the last line mode basic operation
:set nu|nonu Display/ do not display line number: syntaxon |off enable/ disable syntax highlighting:set Hls|nohls on / Turn off query results highlighting: set ai enable auto indent
: Set autoindent enable Auto indent
: Set Noai off Auto indent:set tabstop=4 means tab width is set to 4 spaces
Show ignore or differentiate character case
: Set ignorecase
: Set IC
: Set Noic
Find text to highlight or cancel
: Set Hlsearch
: Set Nohlsearch
Other related documents
In the Vim ~/.VIMRC file
. filename.swp the cache file during the editing process
Vimtutor:vim Course
Configuration file
/etc/VIMRC~/.VIMRC
VIM Completion:
The most common method of completion should be ctrl-n and ctrl-p complement. They look in the current buffer, in other buffers, and in the header files contained in the current file, to find words that begin with the keyword before the cursor. The intelligent complement cannot complement the local variables, while the ctrl-n and ctrl-p complement can be well qualified
Ctrl-p General meaning is upward, so ctrl-p complement is looking up to complete, and ctrl-n is looking down for completion, The speed of completion can be accelerated by using different shortcut keys on different occasions.
Other methods of completion in Vim include:
Complete line completion ctrl-x Ctrl-l based on the key word in the current file to completethe control-X-Ctrl-n based on the dictionary completion of the CTRL-X Ctrl-k based on the synonym dictionary complete Ctrl-X Ctrl-T complements thekey word in the header file Ctrl-X Ctrl-I based on the label completion CTRL-X Ctrl-full file name Ctrl -X-Ctrl-f complement macro definition CTRL-Ctrl-D complete vim command CTRL-X Ctrl-v user-defined completion method CTRL -X Ctrl-u spelling suggestion CTRL-X ctrl-s
You can set these two variables in VIMRC, for example:
2"<C-X><C-O> "
Now you can use tab to complete the completion, like in the shell, the convenience of a lot!
Reference:
https://blog.easwy.com/archives/advanced-vim-skills-auto-complete/
28. Vim Editor