首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

vi在查寻和替换时的转义字符的区别

2012-08-09 
vi在查找和替换时的转义字符的区别http://vim.wikia.com/wiki/VimTip188http://vim.wikia.com/wiki/Search

vi在查找和替换时的转义字符的区别

http://vim.wikia.com/wiki/VimTip188

http://vim.wikia.com/wiki/Search_and_replace

?

When searching:

., *, \, [, ], ^, and $ are metacharacters.+, ?, |, {, }, (, and ) must be escaped to use their special function.\/ is / (use backslash + forward slash to search for forward slash)\t is tab, \s is whitespace\n is newline, \r is CR (carriage return = Ctrl-M = ^M)\{#\} is used for repetition. /foo.\{2\} will match foo and the two following characters. The \ is not required on the closing } so /foo.\{2} will do the same thing.\(foo\) makes a backreference to foo. Parenthesis without escapes are literally matched. Here the \ is required for the closing \).

When replacing:

\r is newline, \n is a null byte (0x00).\& is ampersand (& is the text that matches the search pattern).\1 inserts the text of the first backreference. \2 inserts the second backreference, and so on.

You can use other delimiters with substitute:

:s#http://www.example.com/index.html#http://example.com/#

Save typing by using \zs and \ze to set the start and end of a pattern. For example, instead of:

:s/Copyright 2007 All Rights Reserved/Copyright 2008 All Rights Reserved/

Use:

:s/Copyright \zs2007\ze All Rights Reserved/2008/

热点排行