在vi中搜索一個字符串:
輸入命令:“vi test.txt”
用vi打開一個文本文件。輸入命令:“
/spider”
用ESC鍵進入命令模式,然后輸入一個“/”符號,緊跟着輸入想要搜索的字符串。在這個例子里,我們要搜索的是字符串"spider".點擊按鍵
通過點擊
鍵來找到第一處匹配的字符串。使用“ n ”鍵來尋找到下一處匹配.
在vi中搜索並替換一個字符串:
輸入命令“vi hairyspider.txt”
用vi打開一個文件.
- 輸入命令: “
:%s/swallowed the fly/swallowed a spider to catch the fly/ ”
先用進入命令模式,然后輸入“:%s/findthisstring/replacewiththis/”,把文本中的“findthisstring”替換為“replacewiththis”。
資料來源
===========
http://www.peachpit.com/articles/article.aspx?p=1374386&seqNum=12