As a veteran editor under Linux, vim has been developed for 30 years. During the period of the rise and fall of various editors, only vim has achieved longevity. Vim is definitely a must-have skill on the server. Vim supports pure Keyboard operation can greatly improve the efficiency of editing. However, vim is not friendly to novices, with many operating commands and a steep learning curve, which shut out many non-server developers.
mode
- Normal mode is the source of vim's powerful editing capabilities. The cursor can be moved through hjkl on it. Normal mode commands often require an operator end, such as "dd" to delete the current line, and the second "d" can also be replaced with a move command j Means to delete the current line and the next line.
- Insert mode, in this mode most keystrokes will insert text into the text buffer, and the ESC key can return to normal mode.
- In view mode, the move command can expand the highlighted text area, and the command will be executed on this highlighted text area. The "text object" of vim can also be used in this mode like the move command
Insert mode tips
In vim, you can enter insert mode through a/A/i/I/o/O, and gi can quickly jump to the last edited place and enter insert mode
Fast error correction
- ctrl+h delete the last character
- ctrl+w delete the last word
- ctrl+u delete the current line
move quickly
Move between words
- w/W move to the beginning of the next word
- e/E move to the end of the next word
- b/B move to the beginning of the previous word
Lowercase letters refer to words separated by non-whitespace characters, and uppercase letters refer to words separated by whitespace characters
Move in line
- f{char} move to char character
- t{char} moves to the character before char
- F{char} in turn searches for the preceding character
If you don’t find it the first time, you can use ";"Continue to search for the next one", "Continue to search for the previous one.
0 moves to the beginning of the line, $ moves to the end of the line
Add, delete, modify
Quick delete
- daw delete a word
- dt{char} delete to char
- d$ delete to the end of the line, delete to the beginning of the line,
quick modification
Commonly used commands are r (replace), c (change), s (substitue)
- r replaces a character, s deletes a character and enters insert mode
- c Cooperate with text objects, quickly modify and
quickly query - "/" or "?" to search forward or backward
- "n" or "N" jump to the previous or next match
Search and replace
- "% s/foo/far/g" global scope replaces foo with far
- "1,6 s/foo/far/g" replace line 1-6 foo with far
- "% s/foo//n" query foo match times
Multiple file mode
Switch between buffers
- ls enumerate the current buffer, bn jump to the nth buffer
- bpre bnext bfirst blast
- b buffer_name plus tab completion jump
window
- sp horizontal split, vs vertical split
- ctrl+w+[w|h|j|k|l] to cycle, switch windows up, down, left and right
- e Open a new Buffer in the current window
text object
[number] <comman> [textobject]
number indicates the number of times comman is a command such as d, c, y textobject indicates a text object such as w, s, p
- iw means inner word, aw means a word selects the space after the word
- i(Select the content in the brackets, a(The selected content includes the brackets themselves, the same other brackets and quotation marks are the same
Copy and Paste and Register
- Insert mode paste, :set paste can solve the problem of code indentation disorder
- The default delete and paste will put the content in the "unnamed register"
- Registers can be specified by the "{register} prefix, each of az can be used as a register, and 0 is a special register for copying
- The "+ prefix can use the system clipboard, if vim supports the system clipboard: echo has('clipboard') outputs 1
Macro operation
- The use of macros is divided into recording and playback, q recording q end recording
- q{register} select the register to be saved and save the recording command in it
- @{register} Play back a series of commands saved in the register
- Select multiple lines in visual mode, and play back multiple lines through command mode:'<,'>normal @a
Completion
<ctrl+n>,<ctrl+p>
Complete word<ctrl+x><ctrl+f>
Complete file name<ctrl+x><ctrl+o>
Completing the code needs to turn on the file type check and install the plug-in
Mapping
Vim mapping is to map one operation to another
- nmap/vmap/imap are valid respectively in normal/visual/insert mode
- nnoremap/vnoremap/inoremap respectively represent non-recursive mapping in normal/visual/insert mode
Plug-in
Plugin manager
Install the vim-plug plugin manager, write the plugin script you want to install between the .vimrc file call plug#begin('~/.vim/plugged')
and save and reload the .vimrc and execute it in the command line mode: PlugInstall installationcall plug#end()
Plug 'the plugin you want to install'
Interface beautification
Good-looking interface is pleasing to the eye, keep a happy mood
- Startup interface plugin vim-startify
- Status bar plugin vim-airline
- Indent Line plugin indentLine
- Theme plugin vim-hybrid
Efficiency tools
- Show directory structure nerdtree
- File fuzzy search ctrlp.vim , fzf.vim
- Quick cursor positioning vim-easymotion
- Auto-pairs of brackets and quotes
- Edit vim-surround in pairs
- Search and replace far.vim
- Quick comment vim-commentary
- Autocomplete coc.nvim
- Word highlight vim-interestingwords
Vim IDE
Plug-in camp
VimAwesome is a directory of Vim plugins from GitHub, Vim.org and user submissions. The plug-in usage data is extracted from the dotfiles repos on GitHub.