Home Download Buy Blog Forum Support

Refactor->Rename

Refactor->Rename

Postby gamesurgeon on Sun Apr 29, 2012 1:10 am

Hello,

Is there a way to "rename" a variable through Sublime Text 2? In many IDE's, you can press ctrl-shift-r and rename a variable. Sublime Text 2 appears to recognize variables; when you click on a variable, all variables that appear on that page are outlined in a box.

Thanks,
gamesurgeon
 
Posts: 4
Joined: Sun Apr 29, 2012 1:05 am

Re: Refactor->Rename

Postby nick. on Sun Apr 29, 2012 1:33 am

What you're seeing is just Sublime highlighting all occurrences of the selected word. The program doesn't differentiate between variables, functions, or just plain text, so functionality as you're describing isn't possible. I thought about implementing this as a plugin, where Ctrl+Shift+R does a find/replace for all matches, but that may not be desirable if you use variable names across functions. Your best bet is just Find/Replace within a selected region.
nick.
 
Posts: 266
Joined: Wed Jan 18, 2012 3:45 am

Re: Refactor->Rename

Postby gamesurgeon on Sun Apr 29, 2012 6:47 pm

Argh, that's a shame! Well, thanks for letting me know!
gamesurgeon
 
Posts: 4
Joined: Sun Apr 29, 2012 1:05 am

Re: Refactor->Rename

Postby digitaldavenyc on Tue Jul 17, 2012 2:41 pm

Wouldn't it be possible to differentiate between functions, variables, strings, etc... when performing a refactor? The absence of this feature is a deal breaker for larger teams that work on big code bases.
digitaldavenyc
 
Posts: 2
Joined: Tue Jul 17, 2012 2:38 pm

Re: Refactor->Rename

Postby pete340 on Wed Jul 18, 2012 12:45 pm

digitaldavenyc wrote:Wouldn't it be possible to differentiate between functions, variables, strings, etc... when performing a refactor? The absence of this feature is a deal breaker for larger teams that work on big code bases.


In order to fully differentiate between functions, variable, strings, etc. you need to compile the source code. Even then, renaming has to respect scopes:

int i;

void f() {
int i;
}

Those two i's are two different variables, and renaming one of them must not rename the other.
pete340
 
Posts: 62
Joined: Mon Oct 10, 2011 9:45 pm

Re: Refactor->Rename

Postby digitaldavenyc on Mon Jul 23, 2012 10:19 pm

Yes that's exactly what the editor needs to do, understand the scope of the refactor so you don't unintentionally change variable names outside of your scope. Imaging having a code-base with 20 references to a particular variable in multiple javascript files that for whatever reason need to be refactored. Then having to do it to many functions and variables across the project. Performing this manually is not fun and makes my head hurt when you miss something. This is in other editors such as Eclipse, IntelliJ, etc...
digitaldavenyc
 
Posts: 2
Joined: Tue Jul 17, 2012 2:38 pm

Re: Refactor->Rename

Postby pete340 on Tue Jul 24, 2012 12:03 pm

digitaldavenyc wrote:Yes that's exactly what the editor needs to do, understand the scope of the refactor so you don't unintentionally change variable names outside of your scope. Imaging having a code-base with 20 references to a particular variable in multiple javascript files that for whatever reason need to be refactored. Then having to do it to many functions and variables across the project. Performing this manually is not fun and makes my head hurt when you miss something. This is in other editors such as Eclipse, IntelliJ, etc...


It's not in other editors, it's in IDEs. The difference being that an IDE has a compiler, hence has deep knowledge of the structure of the text. An editor that uses regular expressions to tease apart the text simply is not capable of the analysis needed for refactoring.
pete340
 
Posts: 62
Joined: Mon Oct 10, 2011 9:45 pm

Re: Refactor->Rename

Postby kakyoism on Fri Aug 03, 2012 3:04 pm

Wouldn't it be possible to write a plugin that calls ctags?
kakyoism
 
Posts: 5
Joined: Mon May 07, 2012 1:29 am

Re: Refactor->Rename

Postby alextj on Thu Jan 03, 2013 2:00 pm

I am coming from Code::Blocks and variable renaming seems to work rather well in it. At least in C-language projects.
I do not know how it works there, but I do not use C::B with a compiler (I compile the code manually), so there is no compilation involved.
So far I like Sublime and it would be great if it offered the same variable renaming possibility as C::B.
alextj
 
Posts: 1
Joined: Thu Jan 03, 2013 1:56 pm

Re: Refactor->Rename

Postby Levinaris on Fri May 10, 2013 4:35 pm

I would love this feature as well and would be perfectly happy if it only recognized scope within the file being edited. Speed is important, and going beyond the single file would likely result in too much performance degradation on large projects.
Levinaris
 
Posts: 1
Joined: Fri May 10, 2013 4:32 pm

Next

Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 31 guests