Rename variable and functions in an editor

While coding, I have realized that I change the names of variables and functions a lot (even the names of types). I sometimes find it frustrating to do this with the generic find and replace since sometimes the replace will replace something I didn't want. In addition if I want to change the name of a type that is in a header, I have to go around to all of the files that use this type and do this unreliable search and replace.

For example, I want to change my type real32_t to f32. But since I use this all over the place in multiple files I have to do a manual search and replace in them (though "real32_t" would be easy to replace since it's pretty unique).

One of the great things about IDEs is that they allow you change these names with ease. I'd like to have this functionality, but I really don't want to have to be tied to a specific IDE (or use CMake).

The question, for you guys who use a simple editor like Emacs or VIM (I use VIM), what is your solution for this or do you guys just not run into an issue like this too often? I am surprised Casey never really seemed to mention this problem on his stream (though, I could have missed it). Does this issue just not bother people who use straight editors (should I not be bothered by it)?

I know VIM has a few plugins that can rename variables, but they are very limited since there is no parse tree (except if you use YouCompleteMe, which doesn't seem to have renaming functionality).

Edited by Dan on
There is nothing "simple" about emacs or vim :).

<soapbox>
Since you are already a vim user I'm assuming you know this, but master regex! I don't use them in shipping code too often but I use them when editing and writing quick tools all the time. I am constantly surprised by how many developers know very little about these. We edit text all day!
</soapbox>

For vim, I use two plugins:

https://github.com/mileszs/ack.vim
https://github.com/stefandtw/quickfix-reflector.vim

It is not full blown refactoring support but it usually gets the job done quickly and painlessly.
I don't miss renaming things, but I'm not often working on or refactoring large codebases. Find+replace works ok for me, but I do generally go through one at a time to check what I'm replacing.

A simple trick if you're trying to replace something that gives you a lot false positives is remove your initial definition and let the compiler find all the spots that need to be changed for you.

Like say you were trying to rename a struct that's called Vector2 with the name v2, but you have "Vector2" in almost every function name you're using for some reason and you don't want to modify those... well, you can just rename your definition of Vector2 and then go through all the errors that pop up ("goto next error" shortcut is handy for this).


One thing I do miss about an IDE is like intellisense or whatever you want to call it. It's like having the documentation built right into your editor. That made me very lazy.. :silly:
midnight_mero

One thing I do miss about an IDE is like intellisense or whatever you want to call it. It's like having the documentation built right into your editor. That made me very lazy.. :silly:


Definitely. I guess one of the few good things I can say about Xcode is that it has pretty good code completion. And if you document your classes/functions/variables with Doxygen, option-clicking on them will bring up a popup window with the formatted documentation.

While I do enjoy using Vim for its speed and customizability, it's code completion (clang complete) is unreliable at best, which I find rather irritating.