开发者

Replacing an array in vim

I had an array in my code that's andI I used an index c[i]. I wanted to change c[i] and write g[i][j] in that place. I tried to use the command %s/c[i]/g[i][j]/g but did something unusual.

How can I do such rep开发者_运维知识库lacement in Vim? Thanks in advance.


Put \V into your search expression to go into "very not magic" mode. It can go anywhere in the expression. This makes it so that the only special character in your expression is the backslash. If you're not doing regex matching, or matching begin or end of line, it'll save you a lot of hassle.

%s/\Vc[i]/g[i][j]/g


Since [ and ] are special characters in regular expressions, you need to escape them:

%s/c\[i\]/g[i][j]/g
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜