Sato
Sato

Reputation: 8602

How to change a variable name automatically across the project in VIM?

In eclipse, if you change a variable name, eclipse will automatically change this variable's name in whole project.

Can vim do that too?

Upvotes: 1

Views: 3416

Answers (3)

BB Chung
BB Chung

Reputation: 201

try this plugin -> Clighter, for c-family rename-refactoring. It's based on clang, but there are limitations. Still in development

Upvotes: 0

romainl
romainl

Reputation: 196556

Sort of.

Because it is not an IDE and thus doesn't understand anything about your code, Vim only sees text where you see a variable name. It can't infer anything from the scope or whatever. Without the use of some external program, renaming a variable in Vim is usually done with a buffer-wide or project-wide search/replace.

Since you didn't tell us what language you are working with we can't tell you if there is a language-specific solution for your needs.

Upvotes: 1

Ingo Karkat
Ingo Karkat

Reputation: 172580

Vim is a text editor, not an IDE. Though it has some notion of a filetype's syntax, it does not fully parse nor understand the language's full syntax. Refactorings, even simple ones like Rename identifier, do require such full understanding (to be 100% correct).

There are attempts at refactoring support in Vim, most language-specific, some also generic. But I'd advise to keep using a real IDE for this (for its comfort, safety, and correctness), and instead use Vim only for simple, text-based replacements, using :bufdo substitute/... or macros, as described here.

Upvotes: 3

Related Questions