Vi / VIM: Find And Replace All Text Substitute Command
2016-12-02 13:50
751 查看
Vim: Search and replace syntax
The syntax is as follows::s/Search/Replace/CommandFlag :s/Search-Word/Replace-Word/g :%s/Search-Word/Replace-Word/g :%s/Search-Word/Replace-Word/gc
Examples Text
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT ## full acess to lo and eth0 ## -A INPUT -i lo -j ACCEPT -A OUTPUT -o lo -j ACCEPT -A INPUT -i eth0 -j ACCEPT -A OUTPUT -o eth0 -j ACCEPT # log spoof -A INPUT -i eth1 -s 10.0.0.0/8 -j LOG --log-prefix "IP DROP SPOOF A: " -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP -A INPUT -i eth1 -s 172.16.0.0/12 -j LOG --log-prefix "IP DROP SPOOF B: " -A INPUT -i eth1 -s 172.16.0.0/12 -j DROP
To find each occurrence of
eth0in the current line only, and replace it with
br0, enter (first press
Esckey and type):
:s/eth0/br0/g
To find and replace all occurrences of
eth1with
br1, enter:
:%s/eth1/br1/g
To find and replace all occurrences of
eth1with
br1, but ask for confirmation first, enter:
:%s/eth1/br1/gc
To find and replace all occurrences of case insensitive
eth1with
br1, enter:
:%s/eth1/br1/gi
The above example will find
eth1,
ETH1,
eTh1,
ETh1and so on and replace with
br1.
To find and replace all occurrences of
eth1with
br1for lines from 3 to 7, enter:
:3,7s/eth1/br1/g
A quick demo
相关文章推荐
- VI/VIM text editor 12 Powerful Find and Replace Examples
- Windows Command Line Find and replace - Made easy with FART.exe
- vim find and replace
- Vi and Vim Autocommand: 3 Steps to Add Custom Header To Your File Automatically
- vim separate with . and replace all to end of line
- Vi and Vim Autocommand: 3 Steps to Add Custom Header To Your File Automatically
- [转]Windows Command Line Find and replace - Made easy with FART.exe
- ABAP code to find all the User Exits and BADIs for any transaction
- Vi/Vim Command(修改篇)
- Find and Replace Dialog Boxes 查找和替换对话框
- grails findAll paginate and sortablecolumn
- Substitute and Replace functions in PeopleCode
- open files in a directory and then find someword in the text tcl tk
- 步步为营 .NET 代码重构学习笔记 五、分解函数和替换算法(Replace Method And Substitute Algorithm)
- 在vs2005里面使用regular expression 进行 find and replace操作
- FIND INFO WHERE DATA TYPE IS TEXT AND IS NULL
- vim 使 用 技 巧(vi and vim editors)
- 步步为营 .NET 代码重构学习笔记 五、分解函数和替换算法(Replace Method And Substitute Algorithm)
- Find Text in all columns of all tables in a Database
- 步步为营 .NET 代码重构学习笔记 四、分解函数和替换算法(Replace Method And Substitute Algorithm)