The main contents of this section
- Use of buffers
- File and read disk
- Text Lookup
- Text substitution
Zhou Zhihu L.
Number: Zhouzhihubeyond
NET Name: Rocking Teen Dream
1. Use of buffers
When using Vim for text editing, the edited text will not be saved to the hard disk immediately, but the original file will not be changed unless the file in the buffer is saved. Vim reads the text content into the buffer when the file is opened, and when the text is edited, the modified text is saved in the buffer, and the original file on the hard disk does not change. Let's take a look at the use of buffers.
Let's say that you open two text files with vim:
[email protected]:/home/xtwy# vim test2.txt test1.txt//打开文件后,默认打开的是test2.txt//此时我们使用:buffers命令可以看查缓冲区//得到如下结果:buffers 1 %a "test2.txt" line1 2 "test1.txt" line0
:buffers命令给出的是当前编辑中所有的缓冲区状态,前面的数字是缓冲区的数字标记,第二个标记就是缓冲区当前的状态,紧接着是与缓冲区所关联的文件名。缓冲区的状态有以下几种:- (非活动的缓冲区)a (激活缓冲区)h (隐藏的缓冲区)% (当前的缓冲区)# (交换缓冲区)= (只读缓冲区)+ (已经更改的缓冲区)
In command mode input: Open test1.txt into the Test1.txt edit interface, and then enter: Buffers view buffer status, get the following result
:buffers 1# "test2.txt" line 1 2 %a "test1.txt" line1
You can see that the test1.txt is loaded as an active buffer, while Test2.txt is loaded into the swap buffer. At this point, the bprevious command can toggle test2.txt to the active buffer,
After execution get:
You can see that at this point you have switched back to Text2.txt, and the text2.txt is loaded into the current active buffer, using: buffers command to get the following result:
More buffer operation commands are as follows:
:buffers 电焊工缓冲区状态:buffer 编辑指定缓冲区:ball 编辑所有缓冲区:bnext 到下一缓冲区:bprevious 到前一缓冲区:blast 到最后一个缓冲区:bfirst 到第一个缓冲区:badd 增加缓冲区:bdelete 删除缓冲区:bunload 卸载缓冲区
2. File and read (a) Save and exit
In edit mode, if the text editing task is completed and you want to save the exit directly, return to the Linux CLI command line and press ZZ directly.
(ii) Read the contents of the file into the buffer
In edit mode, use the: R command to read the contents of the file into the current buffer,
: R test1.txt can write Test1.txt file contents to buffer
(iii) write the buffer contents to a file
In edit mode, use the: w command to write the modified file to disk, or you can use: Wq command to write the modified file to disk back out of vim to return to the Inux CLI, if you do not want to save the direct exit, use: q! command to exit vim directly, return to the CLI command line.
3. Text lookup (1) General search
Use the? or/String lookup, for example:
After the carriage return, the cursor will be positioned on the next spark, and if you want to search down, press N (next), or N if you want to search upwards
(2) Regular Expression search
Regular expression search refers to the addition of "^,$." such as special matching characters, they function as follows:
Search String |
Search Description |
Example |
:/^spark |
search for lines starting with Spark |
spark are .... |
:/yarn $ |
search for lines ending in YARN |
|
:/ha...p |
search for Ha beginning with three characters in the middle upper string ending with P |
h Adoop, Hadaap |
:/e> |
|
like, source |
:/\ |
Find the string starting with had, \< also has special meaning |
hadoop, Hadoo |
:/spa * |
\< also has a special meaning |
spark, Spaspark |
:/sp[ae]rk |
match spark or Sperk |
spark, Sperk |
4. Text substitution
Text substitution uses the following syntax format:
:[g][address]s/search-string/replace-string[/option]
Where address is used to specify a replacement scope, the following table shows common examples:
1s/Downloading/Download//将当前缓冲区中的第一行到第五行中的Spark替换为spark:1,5s/Spark/spark//将当前缓冲区中的第一行到当前光标所在行的Spark替换为spark:1sss/Spark/spark//当前行中第一次搜索到的Spark替换为spark: s/Spark/spark//将当前行中所有的Spark替换为spark:s/Spark/spark/g //将所有的ands/\<the\>/The/g
Add a public number to find out more about the latest spark and Scala technical information
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Spark's way of cultivation (basic)--linux Big Data Development Basics: Fifth: VI, VIM editor (ii)