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.)
精彩评论