![vi比较文本 -vim](https://img-blog.csdnimg.cn/img_convert/b3951c03c818edd4357699d8f601ca60.png)
vi比较文本 -vim
Vim is a powerful tool for text editing code developments etc. One of the most wanted and loved features is to find and replace a simple substitute. We will look at different ways to find and replace operation in vim. Our text file named file1
is like below.
Vim是用于文本编辑代码开发等功能的强大工具。最需要和最喜欢的功能之一是找到并替换一个简单的替代品。 我们将研究在vim中查找和替换操作的不同方法。 我们的名为file1
文本文件如下所示。
This is line 1
We can resume
Extra file
Change the station
只需替换为Vim (Simply Replace with Vim)
To work with replace function we need to open the text file with vim and then run replace command.
要使用替换功能,我们需要使用vim打开文本文件,然后运行replace命令。
:%s/line/LINE/g
![](https://img-blog.csdnimg.cn/img_convert/e97fcba35e9839b65e3041eb1defa899.png)
%s will look at all lines for /line occurrence
%s将查看所有行中是否存在/行
/LINE will be replaced with /g flag.
/ LINE将替换为/ g标志。
单行替换 (Replace In Single Line)
If we want to replace only in a single line, not in the whole file we will remove % from command like below. We will change LINE to the line
如果我们只想在一行中而不是整个文件中进行替换,我们将如下所示从命令中删除%。 我们将LINE更改为该行
:s/LINE/line/g