Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refactor in Sublime Text? (Ruby, Rails, JavaScript)

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

like image 310
Daryll Santos Avatar asked Sep 10 '13 12:09

Daryll Santos


People also ask

How do I refactor code in Sublime Text?

You must press ctrl+D again to get additional selections in the file. For mac user: i prefer to use command+D. Press the buttons together multiple times to select the items to refactor.

How do you replace all variables in Sublime Text?

The simplest way: put cursor on name, alt+f3 (select all), then type your new variable name. In case there is multiple stuff named name but you don't want to change them all: put cursor on name, ctrl+d every time you want to accept the selection and ctrl+k,ctrl+d if you want to skip the selection and go to the next.


3 Answers

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.

like image 23
CarlosRos Avatar answered Oct 23 '22 12:10

CarlosRos


I 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.

like image 70
Stephan Ahlf Avatar answered Oct 23 '22 14:10

Stephan Ahlf


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.

like image 5
Daryll Santos Avatar answered Oct 23 '22 14:10

Daryll Santos