当前位置:网站首页>Various uses of vim are very practical. I learned and summarized them in my work
Various uses of vim are very practical. I learned and summarized them in my work
2022-07-07 11:32:00 【Full stack programmer webmaster】
( One ) Primary personalized configuration of your vim
1、vim What is it? ?
vim yes Vi IMproved, It's an editor Vi An enhanced version of , An extremely powerful and consistent IT The engineer ( The programmer 、 Operation and maintenance ) Habitual editor . If you are a professional SE, Then you must be looking for an excellent one that can be customized 、 An editor that meets flexible editing functions . So the answer , Namely vim perhaps Emacs. And this series of blog posts , I'll introduce you vim Editor . As for another powerful editor Emacs, We will see in a series of blog posts in the future .
2、 Where is the configuration file ?
Windows The system configuration file is vim Install under directory vimrc file .
Linux System ,RHEL and CentOS The configuration file is /etc/vimrc,Debian and Ubuntu The configuration file is /usr/share/vim/vimrc.
Mac OS X The configuration file is /usr/share/vim/vimrc.
3、vimRC Medium RC What does that mean? ?
Why do you list such a meaningless problem ? The reason is simple , I'm in touch vim At the beginning, the second question I want to ask is this ( The first one is above “1”). Usually running a certain software 、 At the beginning of the environment or tool , Some to be executed initially command , be called Run Commands, namely RC. according to Wikipedia.org The record ,RC The usage of abbreviations comes from MIT Compatible time-sharing operating system (Compatible Time-Sharing System,CTSS)[ Reference resources 1]. So if you see it later SystemRC perhaps ScreenRC, I know why .
4、 Three basic modes
stay 《 Let's learn vim》 I mentioned vim Yes 6+5 Patterns , But in addition to different levels of segmentation , In fact, only 3 Patterns :Normal Mode、Insert Mode and Command-line Mode.
from Normal Mode Get into Insert Mode, Can press i、I、a、A、o、O、r、R that will do . among i and I Indicates insertion (Insert),r and R To replace (replace).
from Insert Mode Get into Normal Mode, Just press ESC Press the key .
from Normal Mode Get into Command-line Mode, Can press “:”、“/”、“?”. among “:” Indicates input vim command ,“/” Indicates that the string to be searched down is input later ,“?” Indicates that the string to search up is entered later .
from Command-line Mode Get into Normal Mode, Just press ESC Just press the key .
You can take Normal Mode Understood as normal , Enter any other mode , Need some special way , And return from other special modes Normal Mode, Just press the ESC Press the key .
5、vim The most commonly used configurations in
When you try to Google Some others vimrc When the configuration , You will find an article called 《The ultimate vim configuration》 The article , But its author ,Amix Later, he mentioned on his blog [ Reference resources 2], This is in google Search for vimrc Will be in the top ten vim The configuration file , It's out of date now , So he provided some updated information .
(1) color setting
syntax on “ Turn on the code to highlight syntax off “ Turn off code highlighting syntax enable “ Turn on the code to highlight
(2) Search settings
set hlsearch “ Turn on search highlight set nohlsearch “ Turn off search highlighting set incsearch “ Search while entering the search string set ignorecase “ Ignore case when searching
(3) The user interface
set showmode “ On mode display set ruler “ Open cursor position prompt set number “ According to the line Numbers set nonu “ Don't show line numbers set cursorline “ Highlight the line of the cursor set cmdheight=1 “ The height of the command part is 1
(4) Edit auxiliary configuration
set autoindent “ Automatic indentation set noautoindent “ Do not indent automatically set smartindent “ Smart indent set autoread “ When the file is changed externally ,vim Automatic update loading set showmatch “ Show matching brackets
Reference resources :
Run Commands,http://en.wikipedia.org/wiki/Run_commands The Ultimate vim Configuration(vimRC),http://amix.dk/blog/post/19486
( Two ) Commonly used state switching buttons
1、Normal Mode -> Insert Mode
i Lowercase letters i, Insert... At cursor position a Lowercase letters a, Insert... At the next position of the cursor I Capital I, Insert... At the first non space of the line where the cursor is located A Capital A, Insert... At the last character of the line where the cursor is located o Lowercase letters o, Insert a new line next to the line where the cursor is located O Capital O, Insert Singapore Airlines at the upper line of the line where the cursor is located r Lowercase letters r, Replace the character at the cursor once R Capital R, Continue to replace the character at the cursor , Until pressed ESC
2、Normal Mode -> Command-line Mode
:w Save the file :w! Force save file ( The premise is that the user has the permission to modify the file access permission ) :q Exit buffer :q! Force exit from buffer without saving :wq Save the file and exit the buffer :wq! Force save file and exit buffer ( The premise is that the user has the permission to modify the file access permission )
:w Save as named filename file :n1,n2 w take n1 Row to n2 The data of the row is saved as filename file :x If the file changes , Exit after saving . Otherwise, exit directly .
3、Insert Mode -> Normal Mode
Press down ESC key
4、Command-line -> Normal Mode
Press down ESC key
( 3、 ... and ) Commonly used cursor movement keys
1、 Cursor character operation
j Down k Up h towards the left l towards the right $ Move the cursor to the end of the line (End), Pay attention to press Shift key 0 Move the cursor to the beginning of the line (Home) ^ The cursor moves to the first non blank character at the beginning of the line (Home), Pay attention to press Shift key
2、 Cursor word operation
w The cursor moves to the beginning of the next word W The cursor moves to the beginning of the next word and ignores punctuation e The cursor moves to the end of the next word E The cursor moves to the end of the next word and ignores punctuation b The cursor moves to the beginning of the previous word B The cursor moves to the beginning of the previous word and ignores punctuation
3、 Cursor sentence operation
) The cursor moves to the beginning of the next sentence ( The cursor moves to the beginning of the previous sentence % coordination “(” and “)” Use , Look for a matching partner
4、 Cursor line operation
G The cursor moves to the first non blank character on the last line of the document nG The cursor moves to the... Of the document n That's ok , amount to ”:n” gg The cursor moves to the... Of the document 1 The first non blank character of the line , amount to ”1G”, Is equivalent to ”:1″ Cursor down N That's ok
5、 Cursor segment operation
} The cursor moves to the beginning of the next paragraph { The cursor moves to the beginning of the previous paragraph % coordination “(” and “)” Use , Look for a matching partner
6、 Cursor page operation
Ctrl+f Page down (Pagedown) Ctrl+b Page up (Pageup) Ctrl+d Turn down half the page Ctrl+u Turn up half the page H The cursor moves to the first line of the currently displayed page M The cursor moves to the middle line of the currently displayed page L The cursor moves to the last line of the currently displayed page
7、 The cursor operates freely
Ctrl+o Return to the previous position of the cursor
( Four ) Common editing operation keys
1、 Delete operation (delete)
dd Deletes the line where the cursor is located ndd The deletion starts from the line of the cursor , Downward n That's ok d1G The deletion starts from the line of the cursor , All lines to the first line dG The deletion starts from the line of the cursor , All lines to the last line d$ Delete from the cursor position , All characters to the end of the line d0 Delete from the cursor position , All characters to the beginning of the line
2、 Copy operation (yank)
yy Copy the line where the cursor is nyy Copy starts from the line where the cursor is located , Downward n That's ok y1G Copy starts from the line where the cursor is located , All lines to the first line yG Copy starts from the line where the cursor is located , All lines to the last line y$ Copy from the cursor position , All characters to the end of the line y0 Copy from the cursor position , All characters to the beginning of the line
3、 Paste operation (paste)
p Lowercase letters p, Paste the data from the clipboard , Start on the next line of the line where the cursor is located P Capital P, Paste the data from the clipboard , Start from the previous line of the cursor
4、 Undo and redo operations (undo,redo)
u (Undo) Undo the last action Ctrl+r (Redo) Redo last action
5、 Repeat
. Repeat the previous operation
6、 Replace operation (replace)
r Replace the character at the cursor R Go to replace mode , Until you press ESC sign out cc Replace the line of the cursor cw Replace the English word where the cursor is located ~ Convert case
7、 Typesetting operation
:le Align the line of the cursor to the left :ri Align the line of the cursor to the right :ce The line where the cursor is located is centered
( 5、 ... and ) Commonly used multi buffer operation keys
1、 Multi file editing mode
argument list Pattern , Is opening vim Editor time , Carry multiple file path parameters . buffer list Pattern , Is entering vim After editor , Open multiple buffers for editing .
2、 A single buffer opens multiple files
:files Displays which files are currently open :n Switch to the next buffer content :N Switch to the previous buffer content :2n Switch to the next buffer content :bn Next buffer contents (buffer next) :bp Contents of the previous buffer (buffer previous)
3、 Multiple buffers open multiple files
:sp [filename] Open a new buffer , If there is filename Then the content is the file , Otherwise, it is the current file Ctrl+w n Create a new buffer Ctrl+w q Exit the buffer where the cursor is located Ctrl+w j The cursor moves to the next buffer Ctrl+w k The cursor moves to the previous buffer Ctrl+w l The cursor moves to the right buffer Ctrl+w h The cursor moves to the left buffer Ctrl+w v Create a new buffer in the left and right cutting windows Ctrl+w s Cut up and down the window to create a new buffer Ctrl+w o Maximize the buffer where the cursor is located , Other buffers are hidden
( 6、 ... and ) Common search and bookmark shortcuts
1. Search string
/string Search down the string “string”?string Search up the string “string”
2. Repeat last search
n Find the next matching string according to the last search criteria N Find the last matching string according to the last search criteria
3. Search for words
* Search down for the word where the cursor is located ( perfect match )# Search up for the word where the cursor is located ( perfect match )g* Search down for the word where the cursor is located ( Partial matching )g# Search up for the word where the cursor is located ( Partial matching )
4. Bookmark (mark)
ma a It's lowercase , Set the document bookmark for the cursor amA A For capital letters , Set a global bookmark for the cursor A
5. Use bookmarks (mark)
`a To document bookmarks a It's about ,Tab Above key ’a To document bookmarks a At the beginning of the line ,Enter Key left `A To global bookmarks A It's about ,Tab Above key ’A To global bookmarks A At the beginning of the line ,Enter Key left `n If n=0, The buffer will open the last document , And the cursor is at the last position of the last edit ,1-9 And so on ’n If n=0, The buffer will open the last document , And the cursor is at the beginning of the line where the last position was edited ,1-9 And so on
6. View the bookmark list
:marks View all current bookmarks
(7) About encryption
1、 Encrypt your text file
When you use vim When opening or creating a new file , If you add -x Parameters , namely :
vim -x filename
that vim You will be prompted :
Enter entryption key:
When you enter the password ,vim You will be prompted to repeat the input to confirm :
Enter same key again:
When you set your password , In order to * To show , Non plaintext . Next time someone ( Including yourself ) When opening this file ,vim Will prompt :
Need encryption key for “main.cpp” Enter encryption key:
At this time, you just need to enter the password you set before . If you enter the wrong password ,vim It will not prompt you that your password is wrong , Instead, it shows a bunch of meaningless junk code .
2、 Remove encryption and reset password
Open your encrypted file , Then input :
:set key=
such , Your password is set to empty , In the future, you no longer need to enter the password . And if you want to reset the password , You can type :
:X
Notice that it is a capital letter X. At this time vim You will be prompted , Just input the new password twice :
Enter entryption key: ***** Enter sanme key again: *****
3、 Problems caused by encryption
vim The encryption function of , It can be said that there are a lot of problems . such as :
(1) If the password is entered incorrectly ,vim Visitors will not be denied access to edit files . In this case, edit the file and save , The whole document will become chaotic , Unable to identify . In the future, even if you use the correct password to open the file , I can't see the correct document .
(2) If you encrypt a source code file that needs to be compiled , You cannot pass the syntax check of the compiler .
(3) Exchange files cannot be encrypted . What problem does this cause ? The problem is that if other users try to read your exchange file , You can bypass the decryption process , Your encryption is meaningless . The solution is , Do not use exchange files . There are three ways , First, modify your vimrc file (vim The configuration file ):
set noswapfile
Second, in use vim Enter the command at the beginning of opening the file :
vim -x -n filename
( Be careful -x Is the encryption parameter , With what we said swap It doesn't matter. , Don't confuse )
Third, entering vim After editing the file , Input :
But don't use In exchange for The disadvantage of documents is , You may face the tragedy of losing data and being unable to retrieve it . So I want to use encryption , Friends who want not to lose files , Press frequently “:w” Well .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/113811.html Link to the original text :https://javaforall.cn
边栏推荐
- The post-90s resigned and started a business, saying they would kill cloud database
- 正在運行的Kubernetes集群想要調整Pod的網段地址
- 高考作文,高频提及科技那些事儿……
- 面试被问到了解哪些开发模型?看这一篇就够了
- Talk about SOC startup (IX) adding a new board to uboot
- Enclosed please find. Net Maui's latest learning resources
- Web端自动化测试失败的原因
- 常用sql语句整理:mysql
- Unsupervised learning of visual features by contracting cluster assignments
- LeetCode - 面试题17.24 最大子矩阵
猜你喜欢
Table replication in PostgreSQL
Socket socket programming
Using ENSP to do MPLS pseudo wire test
RationalDMIS2022阵列工件测量
通过 Play Integrity API 的 nonce 字段提高应用安全性
基于DE2 115开发板驱动HC_SR04超声波测距模块【附源码】
Web端自动化测试失败的原因
分布式数据库主从配置(MySQL)
普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
In my limited software testing experience, a full-time summary of automation testing experience
随机推荐
Verilog 实现数码管显视驱动【附源码】
深度学习秋招面试题集锦(一)
Verilog realizes nixie tube display driver [with source code]
浙江大学周亚金:“又破又立”的顶尖安全学者,好奇心驱动的行动派
Leetcode - interview question 17.24 maximum submatrix
分布式数据库主从配置(MySQL)
Drive HC based on de2115 development board_ SR04 ultrasonic ranging module [source code attached]
Blog moved to Zhihu
相机标定(1): 单目相机标定及张正友标定基本原理
Apprentissage comparatif non supervisé des caractéristiques visuelles par les assignations de groupes de contrôle
Onedns helps college industry network security
Activity lifecycle
sql里,我想设置外键,为什么出现这个问题
【时间格式工具函数的封装】
聊聊SOC启动(七) uboot启动流程三
聊聊SOC启动(六)uboot启动流程二
Une fois que l'uniapp a sauté de la page dans onlaunch, cliquez sur Event Failure resolution
Avoid mutating a prop directly since the value will be overwritten whenever the parent component
高考作文,高频提及科技那些事儿……
基于Retrofit框架的金山API翻译功能案例