vim program editor
- One, vi and vim
- Second, the use of vi
- Three, vim extra features
- 1. Visual Block
- 2. Multi-file editing
- 3. Multi-window function
- 4. The keyword completion function of `vim`
- 5. ** vim ** Environmental settings and records: ** ~ / .vimrc **, ** ~ / .viminfo **
- 6. *** vim *** Commonly used commands
- Third, other ** vim ** use matters needing attention
- 4. Key review
vi
Is a text editor in command-line mode,
vim
is the advanced version
vi
,
vim
not only can display text in different colors, but also can be carried out, such as
shell
scripting, C language program editor, can be
vim
seen as a program editor,
One, vi and vim
Why study vim
:
- All
UNIX-like
systems will have a built-invi
text editor - Many software editing interfaces will be actively called
vi
vim
With the ability to edit the program, it can actively identify the correctness of the grammar by font color, which is convenient for program design
Second, the use of vi
vi
There are three modes, namely general command mode, edit mode and command line mode
- General command mode
Function: cursor movement, search and replace, delete character, delete entire column, copy entire column, paste entire columnDescription of function keys available in general command mode How to move the cursor [Page Down] Page down [Page Up] Page up 0 or [Home] Move to the first character of this line $ Or [End] Move to the last character of this line G Move to the last line of this file gg Move to the first line of this file n n is a number, representing that the cursor moves down n lines
Description of function keys available in general command mode | Find and replace |
---|---|
/word | Find a word string named under the cursor |
?word | Find a word string named above the cursor |
:n1,n2s/word1/word2/g |
n1 and n2 are numbers, find /word1 this string between n1 and n2 lines , and replace the string withword2 |
:1,$s/word1/word2/g |
Find the word1 string from the first line to the last line and replace it withword2 |
:1,$s/word1/word2/g | Find the word1 string from the first line to the last line , and replace it with word2 , before prompting the characters to confirm to the user whether to replace |
。。。 | 。。。 |
- Edit mode:
function: press any one of the letters [i, I, o, O, a, A, r, R] from the general command mode to enter the edit mode, and insert or replace to edit the content
Description of available function keys for switching from general command mode to edit mode | Enter insert or replace edit mode |
---|---|
i与I |
i To insert from the current cursor position, I to insert at the first non-space of the current line |
a与A |
a To insert A from the next character at the current cursor, to insert from the last character of the line where the cursor is |
o与O |
o To insert a new line o at the current line under the cursor ; to insert a new line for the previous line at the current cursor |
r与R |
Enter replace mode, r it will replace the one character under the cursor once; R would have been replaced by the text cursor until you press Esc up |
[Esc] | Exit edit mode and return to normal command mode |
- Command line mode
Function: Press [:, / ,? from general command mode ] To enter the command line mode, with other additional functions for reading / storing files.
Let ’s learn about thevi
commonly used key functions
Description of available function keys for switching from general command mode to command mode | Command line mode save, exit and other commands |
---|---|
:w |
Write the edited data to the hard disk file |
:w! |
If the file attribute is [read-only], the file is forced to be written. Whether it can be written is related to the file permissions of the file |
:q |
drop outvi |
wq |
Exit after saving, if :wq! yes, force save and exit |
Three, vim extra features
1. Visual Block
How to manipulate data with columns as the operating unit?
Key meaning of visual blocks | |
---|---|
v |
Character selection, will highlight the place where the cursor passes |
V |
Line selection, the line passing by the cursor will be highlighted |
[Ctrl]+v |
Visualize blocks, you can select data in a rectangular way |
y |
Copy the highlights |
d |
Delete the highlight |
p |
Paste the block you just copied at the cursor position |
2. Multi-file editing
vim
Several files are connected at the same time to open at the same time. The related keys are:
Buttons for multi-file editing | |
---|---|
:n | Edit next file |
:N | Edit last file |
:files | List all files currently opened by this vim |
3. Multi-window function
4. vim
Keyword completion function
vim
Completing the functions, there are roughly the following:
Key combination | Completed content |
---|---|
[ctrl]+x —>[ctrl]+n |
Use the [text of the document] that is currently being edited as a keyword to complete |
[ctrl]+x--->[ctrl]+f |
Use [file name] in the current directory as a key word to complete |
[ctrl]+x--->[ctrl]+o |
Add the extension as a grammatical supplement and fill in with the vim built-in keywords |
Note: The extension of .html
or must be used .php
, otherwise the vim
correct syntax check function will not be called.
5. Vim environment settings and records: /.vimrc**, ** /. Viminfo
vim
The setting value of is generally placed in the /etc/vimrc
file, it is generally not recommended to modify
6. *** vim *** Commonly used commands
[External chain image transfer failed, the source site may have an anti-theft chain mechanism, it is recommended to save the image and upload it directly (img-tBqBzts9-1586392123529) (C: \ Users \ lee \ Desktop \ vim common command schematic.jpg)]
Three, other vim use matters needing attention
vim
Although it is powerful, there are some places to pay attention to below
1. The problem of Chinese encoding
由于编码的问题,vim
有时候会无法正常显示正常的中文。
vim
的终端界面中使用的是UTF-8
,由于编码的不同,中文内容便会显示一堆乱码,这时候需要考虑一下几点:
- Linux系统默认支持的语系数据,与
/etc/locale.conf
有关 - 终端(bash)的语系,与LANG、LC_ALL几个变量有关
- 文件原本的编码
- 打开终端的软件,例如GNOME下面的窗口界面
2.DOS与Linux的换行符
两者的字符定义不同,不建议在Windows
系统中将文件编辑好之后再上传到Linux
系统。当对文本文件进行复制时,需要使用unix2dos
或dos2unix
转换行格式
3.语系编码转换
iconv
命令可以将语系编码进行转换
四、重点回顾
Linux
下面的配置文件多为文本文件,故使用vim
即可进行设置编辑vim
可视为程序编辑器,可用以编辑shell
脚本,配置文件等,避免打错字vi
有三种模式,包括命令模式,编辑与命令行模式,常见的按键有i
、[Esc]
、wq
等vi
的替换功能,例如:n1,n2s/old/new/g
- 进入编辑模式几乎只要记住:i,o,R三个按键即可,尤其是新增一行的o与替换的R
vim
的环境设置可以写入在~/.vimrc
文件中- 可以使用
iconv
进行文件语系编码的转换 - 使用
dos2unix
及unix2dos
可以变更每一行的行尾换行符
R三个按键即可,尤其是新增一行的o与替换的R vim
的环境设置可以写入在~/.vimrc
文件中- 可以使用
iconv
进行文件语系编码的转换 - 使用
dos2unix
及unix2dos
可以变更每一行的行尾换行符 - 对于文章内有对齐的区块,可使用
[ctrl]-v
进行复制,粘贴,删除的操作