Spark's way of cultivation (basic)--linux Big Data Development Basics: Sixth: VI, VIM Editor (second) (reproduced)

Source: Internet
Author: User

Transferred from the cloud habitat: Https://yq.aliyun.com/articles/60354?spm=5176.8251999.569296.36.siyXRn Zhou Zhihu Lake2015-08-25 21:23:00 Browse 305 Reviews 0

Abstract: This section of the main content of the buffer of the use of the file and read the text to find text replacement Zhou Zhihei: Zhouzhihubeyond: Swing Juvenile Dream 1. Buffer use when using Vim for text editing, the edited text is not immediately saved to the hard disk, but saved in the buffer, if not the buffer file, the original file will not be changed. Vim reads the text content into the buffer when the file is opened and, when the text is edited, repairs the

The main contents of this section
    1. Use of buffers
    2. File and read disk
    3. Text Lookup
    4. 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" line 1 2 "test1.txt" line 0

: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" line 1

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 that start with spark Spark is ....
:/yarn$ Search for lines that end in yarn ... Hadoop YARN
:/HA...P Search for HA beginning with three characters in the middle upper string ending with P Hadoop, Hadaap
:/e> Finds a string ending with E, where the > symbol is the end of the string indicator, where \ is not an escape character, but is combined with > to represent a special meaning Like, source
:/\<Had Finding a string that starts with had \< also has a special meaning Hadoop, Hadoo
:/Spa* It \< also has a special meaning to look at at least one spar string in the string. 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:

1 s/Downloading/Download//将当前缓冲区中的第一行到第五行中的Spark替换为spark:1,5 s/Spark/spark//将当前缓冲区中的第一行到当前光标所在行的Spark替换为spark:1,. s/Spark/spark//将当前光标所在行到缓冲区最后一行的Spark替换为spark:.,$ s/Spark/spark//将整个缓冲区中的Spark替换为spark:% s/Spark/spark//当前行中第一次搜索到的Spark替换为spark: s/Spark/spark//将当前行中所有的Spark替换为spark:s/Spark/spark/g //将所有的and转换成And,不包括theta这种字符串,只会作用于the这种单独存在的字符串:% s/\<the\>/The/g 

Add a public number to find out more about the latest spark and Scala technical information

Spark cultivation Path (Basic)--linux Big Data Development Basics: Sixth: VI, VIM Editor (ii) (reprint)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.