Replacing an array in vim

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

How can I make such a replacement in Vim? Thanks in advance.

+3
source share
2 answers

Put a \Vsearch in your expression to switch to "not very magical" mode. It can go anywhere in the expression. This makes the backslash the only special character in your expression. If you don't match regular expressions or match the beginning or end of a line, this will save you a lot of trouble.

%s/\Vc[i]/g[i][j]/g
+7
source

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

%s/c\[i\]/g[i][j]/g
+7
source

Source: https://habr.com/ru/post/1763238/


All Articles