How to quickly change variable names in Vim?

前端 未结 7 1889
庸人自扰
庸人自扰 2020-12-12 08:55

I am using Vim to read through a lot of C and Perl code containing many single letter variable names.

It would be nice to have some command to change the name of a va

相关标签:
7条回答
  • 2020-12-12 09:22

    AFAIK, there is no actual refactoring support in VIM. When doing a rename with the intent of a refactor I usually take the following precautions:

    1. Limit the scope of the change my using marks.
    2. When entering the regex, bracket the name with \< and >. This will make it match an entire word which reduces the types of incorrect renames that will occur.
    3. Don't do a multiline replace to reduce chances of a bad replace
    4. Look through the code diff carefully if it's anything other than a small change.

    My end change looks something like this

    :'a,'bs/\<foo\>/bar
    

    I would love to be wrong about there not being a refactoring tool for VIM but I haven't seen it.

    0 讨论(0)
提交回复
热议问题