admin管理员组文章数量:1334290
I used Netbeans before. How do I do some refactoring (changing variable names, make method out of code, etc) in Sublime Text 2 on a Mac? What I'm doing right now is "select next instance of a word", but that's only because I'm using only one file
I used Netbeans before. How do I do some refactoring (changing variable names, make method out of code, etc) in Sublime Text 2 on a Mac? What I'm doing right now is "select next instance of a word", but that's only because I'm using only one file
Share Improve this question asked Sep 10, 2013 at 12:08 Daryll SantosDaryll Santos 2,0813 gold badges23 silver badges42 bronze badges6 Answers
Reset to default 8I wrote this plugin for JavaScript refactoring https://github.com/s-a/sublime-text-refactor
I guess there are a lot more out there supporting RoR.
What works for me is the "Find all" option (Ctrl+F and Alt+Enter).
This way you can edit the text and all the matches will be edited at same time.
What happened here was that I just did refactoring via grepping and find/replace. I'm on Vim now and substitute/grepping is still my method when I need to refactor. I guess this is one of the features that an IDE provides that a text editor doesn't.
Alongside ctrl+click you can use ctrl+D also. Works for me.
What I do is select multiple variables with ctrl+click and the once you type, all selected strings are changes. The only difference is that you need to select them manually. But then again -- once you select the first one, all matching variables are highlighted
The sublime-text-refactor
plugin works as long as you need to refactor variables. If you need to refactor plain strings it doesn't work. For example if you need to replace 'components'
in file paths 'file/*/components'
by 'sections'
the plugin will not help you because it expects to rename variables (console indicates when I try to refactor: unable to locate components
variable).
My answer is not related to sublime text but I was led to this thread when I found the adapted solution so it might help people in the same case. Sublime text is not necesarily the solution for refactoring.
In NodeJs, what I did to ensure refactor across files was to create a gulp task that replaces the value and rewrites the file:
var gulpReplace = require('gulp-replace');
gulp.task('refactor', function(){
gulp.src(['app/**/*.js'], { base: './' })
.pipe(gulpReplace(/components/g, 'sections'))
.pipe(gulp.dest('./'));
});
$gulp refactor
What this does is that, in all js files under the app
directory, I replace the string 'components'
by the string 'sections'
. In my case I needed plain string replacement, it was not variable renaming so the need was very straightforward and this method is very efficient for that. Adapt this method to your case and back up your code before you refactor, as it is the equivalent to find/replace via grep, there is no prior check, be sure of what you're doing.
I advise to delete the gulp task once you are done with your refactoring as it can be very dangerous ! CAUTION
本文标签: How to refactor in Sublime Text (RubyrailsJavascript)Stack Overflow
版权声明:本文标题:How to refactor in Sublime Text? (Ruby, Rails, JavaScript) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738010689a2048858.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论