国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > 互联网 > vim编辑器替换功能详解

vim编辑器替换功能详解

来源:程序员人生   发布时间:2015-06-04 07:34:41 阅读次数:2209次

转载自http://www.uhdesk.com/?p=29


he substitute command searches for a text pattern, and replaces it with a text string. There are many options, but these are what you probably want:


:%s/foo/bar/g
Find each occurrence of ‘foo’ (in all lines), and replace it with ‘bar’.


:s/foo/bar/g
Find each occurrence of ‘foo’ (in the current line only), and replace it with ‘bar’.


:%s/foo/bar/gc
Change each ‘foo’ to ‘bar’, but ask for confirmation first.


:%s/<foo>/bar/gc
Change only whole words exactly matching ‘foo’ to ‘bar'; ask for confirmation.


:%s/foo/bar/gci
Change each ‘foo’ (case insensitive) to ‘bar'; ask for confirmation.
This may be wanted after using :set noignorecase to make searches case sensitive (the default).


:%s/foo/bar/gcI
Change each ‘foo’ (case sensitive) to ‘bar'; ask for confirmation.
This may be wanted after using :set ignorecase to make searches case insensitive.
The g flag means global

生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生