开发者

vim command for search and substitute

This is开发者_高级运维 my question.

In vim editor I want to select all the words between double quotes through out the whole file and i want to replace the selected words by preceding that with gettext string. Please anybody tell me vim command to do this.

for ex: if the file contains

printf("first string\n"); printf("second string\n");

After replacement my file should like this

printf(gettext("first string\n")); printf(gettext("second string\n"));


You should be able to do:

s/\".\{-}\"/gettext\(\1\)/g


try this in vim:

:%s/\(".*"\)/gettext(\1)/g

Here \( and \) is being used to group the text and \1 is then used to put 1st backreference back along with gettext function.


in command mode:

:%s!"\([^"]*\)"!gettext("\1")!g

the % is for whole document, [^"]* for anything except quotes, and the g at the end for all occurence in the line (default is only the first one). The separator char can be anything not in the regexp... I often use ! rather than / (more convenient when dealing with path e.g.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜