ITmeze
ITmeze

Reputation: 1922

How to refactor code without IDE functionality (in Vim or TextMate)?

I wonder how do programmers refactor code that is written in languages like Ruby, Python?

Assuming you get code after a 'previous' guy—so you cannot be sure about quality of tests and their coverage.

Do you use any specific approach?

Upvotes: 3

Views: 1692

Answers (3)

Tarsis Azevedo
Tarsis Azevedo

Reputation: 1523

To refactor code in Python, you can use RopeVim.

Upvotes: 1

Carl Manaster
Carl Manaster

Reputation: 40336

Without an IDE, you will have to take smaller steps, well protected by comprehensive unit tests. Martin Fowler's Refactoring, written before all the software tools were available, is a pretty good guide to how to refactor safely. You take small steps, checking all along that you're not breaking anything, frequently leaving original code in place until the replacement has been completed. It's tedious but doable.

Upvotes: 3

Stephen Furlani
Stephen Furlani

Reputation: 6856

in vim you can use the following command to search for things:

/spock

and get all instances of spock by pressing n to cycle through the file.

To search and replace, you can use this:

:%s/spock/kirk/g

which will replace all instances of spock with kirk. Vim has some pretty powerful stuff, but you can also use find/sed/grep to do entire directories or projects.

Good luck!

Upvotes: -1

Related Questions