For example, if I have the following:
MY_VAR = "hello world" print "the var %s" % MY_VAR
If I position the cursor on
MY_VAR and press
*, Vim highlights both matches. Suppose I want to rename this to
HELLO_WORLD_VAR, how might I achieve this?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
Since you pressed
*, your last search was for
MY_VAR, i.e. equivalent to
/MY_VAR. If you don't specify a search pattern in a substitution, the last search pattern is used, which is
MY_VAR in your case. So you can simply use
:%s//HELLO_WORLD_VAR/g to do the renaming.
Note that I used the
g flag to indicate that all occurences should be replaced, not only the first on any line. It's not neccessary in your case, but probably makes sense in another context.