当前位置:网站首页>VIM super practical guide collection of this one is enough
VIM super practical guide collection of this one is enough
2022-07-02 12:51:00 【ICER Xiaoshi tablet】
vim It's a Unix Text editor , It is famous for being fast and efficient , It is a small application running in the terminal ( Of course, there is also a graphical interface ), Its main feature is that it can be controlled by keyboard , You don't need a menu bar or mouse .
for example , Insert text into the file , Press i Key and enter . Browse the text or enter a command , Press on the keyboard Esc, Then press any corresponding key or key combination . For most people , Is a very unusual way of text editing , But it's based on Linux Developers working in the environment edit configuration files 、 Change the script 、 The mainstream way of writing code and other operations .
This article will introduce some necessary basic commands , So that we can quickly and easily grasp vim Editor . It is suggested that beginners learn while using , Instead of just looking at nothing . Non actual operation , Then you may soon forget these orders .

Use vim After opening the file , Three modes are generally used : Command mode (command mode)、 The input mode (insert mode) And the bottom line command mode (last line mode). Just started vim when , Enter command mode by default . Now , The letters we type on the keyboard will be recognized as different commands . Such as Direction key h、j、k、l; Input key i、a、o, Switch to input mode ; Colon keys :, Switch to the bottom line command mode .
Enter input mode , You can code in letters at will 、 Symbol , Press esc key Exit to command mode . In the bottom line command mode , You can enter a single or multiple commands , Press enter key End operation .

1、vim The entry and exit of :vi、vim、:q、:q!、:wq stay terminal Directly knock vi or vim Open text
:q Exit file
:q! Force exit file , Discard any changes you make
:wq Save changes , Then exit the file
2、 Move the cursor :h、j、k、l key h Move left 、l Move right 、j Move down 、k Move upward , Skillfully use hjkl key , After getting used to it, we can quickly move the cursor around the screen .
3、 Insert 、 Delete and undo :i、A、x、u key 、ctrl+r
stay command In mode : Press down i key Can enter the insert Pattern , Insert text after the cursor , When the input is complete, press esc key (A key , Move the cursor to the end of the line and enter ); Press down x key You can delete the character where the cursor is located ; Press down u key You can undo the operation , Go back to the previous step .ctrl+r Undo the undo order . Press down esc Key will return to command Mode or undo a command that you don't want to enter or partially complete .
4、 Delete class Command :dw、d$、dd
dw Delete from the cursor to the end of a word
d$ Delete from the cursor to the end of the line
dd Deletes the line where the cursor is located
5、 Entering a number before the action will make the operation repeat so many times 3dd Execute the cursor line three times , That is, delete the next three lines
2w Move the cursor forward two words
0 Move to the beginning of the line of the cursor
6、 About location and file status gg Skip to the first line of the file G / shift+g Skip to the last line of the file ctrl+g Displays the name of the currently edited file and the cursor position in the file gf Enter the file where the cursor is located
7、 About search commands / Adding a string can be used to find the string in the current file ? For reverse lookup
for example :/error < enter > You can find it in the file errorn key Continue searching down ,N Key or shift+n key Keep searching up (shift+ A lowercase letter = Capitalization )
8、 Replace the command :s/old/new/g g It is necessary to learn and apply more to match multiple operations globally
9、 stay vim Internal execution of external orders Input :! Then enter an external command to execute all of the external commands : All orders must be given by knocking Enter key end
10、 Using operators y Copy text , Use p Paste text
Using multi line operation with visual mode is often used , Bear in mind !
11、set Set some options :set xxx You can set xxx Options . Some useful options are as follows :'ic' 'ignorecase' Ignore letter case when searching 'is' 'incsearch' Show partial matches when looking for phrases 'hls' 'hlsearch' Highlight all matching phrases
12、 Get online system help
There are three ways :- Press down <HELP> key ( If there is one on the keyboard )- Press down <F1> key ( If there is one on the keyboard )- Input :help < enter >
13、 Enable more vim Characteristics of Vim It's more functional than Vi A lot more , But most of them are not enabled by default . In order to use more features , You need to create a vimrc file .
1. Start editing vimrc file , The specific command depends on the operating system used ::edit ~/.vimrc This is a Unix Commands used by the system :edit $VIM/_vimrc This is a MS-Windows Commands used by the system
2. Then read vimrc The contents of the sample file ::r $VIMRUNTIME/vimrc_example.vim
3. Save the file , The order is ::write
Next start Vim when , The editor will have the function of syntax highlighting . You can add your favorite settings to this vimrc In file . To learn more, type :help vimrc-intro
14、 Use <tab> Key to complete the command line
Completion works for many orders , When the input : On command ,tab key Can match and complete .
15、vim It comes with a tutorial description , We can type in vimtutor, Open the tutorial and do the corresponding exercises .
overall situation
- :h[elp] keyword - Open keyword help
- :sav[eas] file name - Save as
- :clo[se] - Close the current window
- :ter[minal] - Open one shell window
- K - Open the word where the cursor is located man page
Move the cursor
- h - Move the cursor left
- j - Move cursor down
- k - Move the cursor up
- l - Move the cursor right
- H - Move to the top of the current page
- M - Move to the middle of the current page
- L - Move to the bottom of the current page
- w - Move to the beginning of the next word
- W - Move to the beginning of the next word ( Words with punctuation )
- e - Move to the end of the next word
- E - Move to the end of the next word ( Words with punctuation )
- b - Move to the beginning of the previous word
- B - Move to the beginning of the previous word ( Words with punctuation )
- ge - Move to the end of the previous word
- gE - Move to the end of the previous word ( Words with punctuation )
- % - Jump to the paired symbol ( Pairing symbol group supported by default :: '()', '{}', '[]' - stay vim Use in :h matchpairs Get more information )
- 0 - Move to beginning of line
- ^ - Non blank character moved to the beginning of the line
- $ - Move to end of line
- g_ - Move to the last non blank character in the line
- gg - Move to the first line of the file
- G - Move to the last line of the file
- 5gg or 5G - Move to line 5
- gd - Jump to local definition
- gD - Jump to the global definition
- fx - Move to character x Next place
- tx - Move to character x The previous character of the next occurrence position
- Fx - Move to character x Where it last appeared
- Tx - Move to character x The last character of the last occurrence
- ; - Repeat previous f、t、F、T operation
- , - Reverse repeat the previous f、t、F、T operation
- } - Move to the next paragraph ( When editing code, it is a function / Code block )
- { - Move to the previous paragraph ( When editing code, it is a function / Code block )
- zz - Move the screen to center the cursor
- Ctrl + e - Move the screen down one line ( Keep the cursor still )
- Ctrl + y - Move the screen up one line ( Keep the cursor still )
- Ctrl + b - Scroll up one screen
- Ctrl + f - Scroll down one screen
- Ctrl + d - Scroll down half screen
- Ctrl + u - Scroll up half screen
Insertion mode - Insert / Add text
- i - Insert characters from the front of the cursor
- I - Insert characters from the beginning of the line
- a - Insert characters from behind the cursor
- A - Insert characters from the end of the line
- o - Start another line below the current line , Start inserting characters
- O - Start another line above the current line , Start inserting characters
- ea - Insert from the end of the current word
- Ctrl + h - In insert mode , Delete the character before the cursor
- Ctrl + w - In insert mode , Delete the word before the cursor
- Ctrl + j - In insert mode , Another line
- Ctrl + t - In insert mode , Indent right , Width by shiftwidth control
- Ctrl + d - In insert mode , Indent left , Width by shiftwidth control
- Ctrl + n - In insert mode , Insert the next match of automatic completion before the cursor
- Ctrl + p - In insert mode , Insert the last match of automatic completion before the cursor
- Ctrl + rx - Insert register x The content of
- Ctrl + ox - Temporarily enter normal mode to issue a normal mode command x.
- Esc - Exit insertion mode
Edit text
- r - Replace the current character
- R - stay ESC Before pressing , Replace multiple characters
- J - Merge the next line into the current line , And insert a space between the two parts of the text
- gJ - Merge the next line into the current line , There is no space between the two parts of text
- gwip - Readjust the paragraph
- g~ - switch case up to motion
- gu - Lowercase operation modifier
- gU - Upper case operation modifier
- cc - Delete the line where the cursor is located , Then enter insertion mode
- C - Delete from the cursor to the end of the line , Then enter insertion mode
- c$ - Delete from the cursor to the end of the line , Then enter insertion mode
- ciw - Delete the word where the cursor is located , Then enter insertion mode
- cw or ce - Start at cursor position , Modify the word
- s - Delete the current character , Then enter insertion mode
- S - Clear the current line , Then enter insertion mode ( Same as cc)
- xp - Move the current character back
- u - revoke
- U - Undo the last operation of changing the line
- Ctrl + r - redo ( Cancel cancellation )
- . - Execute the last command again
Select text ( Visualization mode )
- v - Enter visualization mode , Move the cursor to highlight the selection , You can then execute commands on the selected text
- V - Enter visualization mode ( Row granularity selection )
- o - Switch the cursor to the beginning of the selection area / ending
- Ctrl + v - Enter visualization mode ( Matrix selection )
- O - Switch the cursor to the corner of the selection area
- aw - Choose the current word
- ab - Choose to be () The area of the package ( Bracketed )
- aB - Choose to be {} The area of the package ( With curly brackets )
- at - Choose to be <> Label the area of the package ( contain <> label )
- ib - Choose to be () The area of the package ( Without brackets )
- iB - Choose to be {} The area of the package ( No curly braces )
- it - Choose to be <> Label the area of the package ( Not included <> label )
- Esc - Exit visualization mode
Visualization mode command
- > - Indent right
- < - Indent left
- y - Copy
- d - shear
- ~ - Case Toggle
- u - Convert the selected text to lowercase
- U - Convert the selected text to uppercase
shear , Copy , Paste
- yy - Copy the current row
- 2yy - Copy 2 That's ok
- yw - Copy the current word
- yiw - Copy the word at the cursor
- yaw - Copy the word at the cursor and the space before and after it
- y$ - Copy , From the cursor position to the end of the line
- p - Paste after the cursor
- P - Paste in front of the cursor
- dd - Cut the current line
- 2dd - shear 2 That's ok
- dw - Cut the current word
- diw - Delete the word at the cursor
- daw - Delete the word at the cursor and the space before and after it
- D - shear , From the cursor position to the end of the line
- d$ - shear , From the cursor position to the end of the line ( Same as <kbd>D</kbd>)
- x - Cut the current character
Indent words
- >> - Indent the current line to the right , Width by shiftwidth control
- << - Indent the current line to the left , Width by shiftwidth control
- >% - Indent right () or {} The area within ( The cursor should be placed in brackets )
- >ib - Indent right () The area within
- >at - Indent right <> The area within the label
- 3== - Automatic indentation 3 That's ok
- =% - Automatic indentation () or {} The area within ( The cursor should be placed in brackets )
- =iB - Automatic indentation {} The area within ( The cursor should be placed in brackets )
- gg=G - Automatically indent the entire buffer
- ]p - Paste and adjust indent to current line
sign out
- :w - preservation
- :w !sudo tee % - Use sudo Save the current file
- :wq or :x or ZZ - Save and exit
- :q - sign out ( Warning if modifications are not saved )
- :q! or ZQ - Force exit without saving
- :wqa - Save all tabs and exit all
lookup / Replace
- /pattern - lookup <kbd>pattern</kbd>
- ?pattern - Upward search <kbd>pattern</kbd>
- n - Find the next one
- N - Find the last one
- :%s/old/new/g - Replace all
- :%s/old/new/gc - ( one by one ) Replace
- :noh[lsearch] - Remove highlighting from search results
multifile search
- :vim[grep] /pattern/{`{file}`} - Search multiple files <kbd>pattern</kbd>
- :cn[ext] - Move to the next
- :cp[revious] - Move to the previous
- :cope[n] - Open the search results list
label
- :tabnew or :tabnew {page.words.file} - Open the file in the new tab
- Ctrl + wT - Turn the window into a label
- gt or :tabn[ext] - Switch to the next tab
- gT or :tabp[revious] - Switch to the previous tab
- #gt - Switch to <kbd>#</kbd> A label
- :tabm[ove] # - Move the tag to <kbd>#</kbd> position ( Subscript from 0 Start )
- :tabc[lose] - Close current label
- :tabo[nly] - Close other tabs
- :tabdo command - Execute commands in all tags
Multi file editing
- :e[dit] file name - New buffer open filename
- :bn[ext] - Switch to the next buffer
- :bp[revious] - Switch to the previous buffer
- :bd[elete] - Close buffer
- :ls or :buffers - List all open buffers
- :sp[lit] file name - New buffer open filename And split the window horizontally
- :vs[plit] file name - New buffer open filename And split the window vertically
- :vert[ical] ba[ll] - edit all buffers as vertical windows
- :tab ba[ll] - edit all buffers as tabs
- Ctrl + ws - Split the window horizontally
- Ctrl + wv - Split the window vertically
- Ctrl + ww - Switch between windows
- Ctrl + wq - close window
- Ctrl + wx - Switch the window to the next window
- Ctrl + w= - Make all windows equal in height and width
- Ctrl + wh - Switch to the left window
- Ctrl + wl - Switch to the right window
- Ctrl + wj - Switch to the lower window
- Ctrl + wk - Switch to the upper window
- Ctrl + wH - Make the window where the cursor is located full height and move to the leftmost ( Leftmost vertical window )
- Ctrl + wL - Make the window where the cursor is located full height and move to the rightmost ( Rightmost vertical window )
- Ctrl + wJ - Make the full width of the window where the cursor is located and move to the bottom ( Bottom horizontal window )
- Ctrl + wK - Make the full width of the window where the cursor is located and move it to the top ( Top horizontal window )

Quickly order a compliment and collection , In case you get lost !!!
边栏推荐
- JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
- js3day(数组操作,js冒泡排序,函数,调试窗口,作用域及作用域链,匿名函数,对象,Math对象)
- Heap acwing 838 Heap sort
- Ntmfs4c05nt1g N-ch 30V 11.9a MOS tube, pdf
- 趣味 面试题
- 线性DP AcWing 898. 数字三角形
- Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
- Interesting interview questions
- Floyd AcWing 854. Floyd finds the shortest path
- Hash table acwing 841 String hash
猜你喜欢
![2.7 binary tree, post order traversal - [FBI tree]](/img/6b/1ded3632cc69329d7b2762ce47fdbc.jpg)
2.7 binary tree, post order traversal - [FBI tree]

Dijkstra AcWing 850. Dijkstra finding the shortest circuit II

哈希表 AcWing 840. 模拟散列表

Async/await asynchronous function

浏览器node事件循环

上手报告|今天聊聊腾讯目前在用的微服务架构

Hash table acwing 841 String hash

Modular commonjs es module

线性DP AcWing 902. 最短编辑距离

In development, why do you find someone who is paid more than you but doesn't write any code?
随机推荐
堆 AcWing 838. 堆排序
bellman-ford AcWing 853. Shortest path with side limit
Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)
Five best software architecture patterns that architects must understand
Package management tools
区间DP AcWing 282. 石子合并
Shutter encapsulated button
Redis introduction, scenario and data type
BOM DOM
About asp Net MVC project in local vs running response time is too long to access, the solution!
Anxiety of a 211 programmer: working for 3 years with a monthly salary of less than 30000, worried about being replaced by fresh students
LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
Redis avalanche, penetration, breakdown
Fluent fluent library encapsulation
Anti shake throttle
"As a junior college student, I found out how difficult it is to counter attack after graduation."
Deep copy event bus
线性DP AcWing 896. 最长上升子序列 II
Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
上手报告|今天聊聊腾讯目前在用的微服务架构