Eclipse shortcuts for Sublime Text 2

We are a Linux shop. We tried to pimp gedit with all plugins under the sun in an effort to transform it into TextMate, but no matter what we try it keeps being an awkward coding experience. Still on the search for alternatives, last month we discovered Sublime Text 2 and its entire new way of understanding text editing.

Sublime Text is just perfect for lightweight coding at times where a full-blown IDE is overkill: after all, it makes little sense to open Eclipse if you are going to spend the next eight hours debugging JavaScript or HTML (Agile and all that).

I work with multiple major projects in the same week, performing different tasks and roles. I switch environments a lot. Having to think "where am I editing?" before duplicating lines or saving files was messing into my flow.

So, without further ado, behold the

Ultimate eclipse shortcuts for Sublime Text 2

Not exactly rocket science, but still: go to Preferences > Key bindings > User and paste this (replacing ctrl with super for Mac):

 { "keys": ["shift+enter"], "command": "run_macro_file", "args": {"file": "Packages/Default/Add Line.sublime-macro"} },
 { "keys": ["alt+up"], "command": "swap_line_up" },
 { "keys": ["alt+down"], "command": "swap_line_down" },
 { "keys": ["ctrl+alt+j"], "command": "join_lines" },
 { "keys": ["ctrl+alt+down"], "command": "duplicate_line" },
 { "keys": ["shift+ctrl+r"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true} },
 { "keys": ["ctrl+shift+s"], "command": "save_all" },
 { "keys": ["ctrl+l"], "command": "show_overlay", "args": {"overlay": "goto", "text": ":"} },
 { "keys": ["shift+ctrl+f4"], "command": "close_all" },
 { "keys": ["shift+ctrl+y"], "command": "lower_case" },
 { "keys": ["shift+ctrl+x"], "command": "upper_case" },
 { "keys": ["ctrl+d"], "command": "run_macro_file", "args": {"file": "Packages/Default/Delete Line.sublime-macro"} }

Save, and you will have a selection of finest eclipse shortcuts configured right into your editor. It is as far as I could get without getting into macros. You can help yourself and find the complete list of commands under Preferences > Key bindings > Global, and complement this with our own discoveries.

If you like this, do not miss our new post about Sublime Text Editor tips.

Addendum: Ctrl+Alt+Down
(a contribution by Hugh Campbell)

The behaviour for the the Duplicate Lines ctrl-alt-down command can be more accurately matched to the Eclipse version (that dupes whole lines, not just the selected text) by defining a macro that selects the lines in question first, then executes the duplicate.

The macro (based on the delete line example above):

{"command": "expand_selection", "args": {"to": "line"}},
{"command": "duplicate_line"}

Save this to your User Packages folder (Preferences > Browse Packages > User folder) as Duplicate Lines.sublime-macro, then edit the command keys to give you:

{ "keys": ["ctrl+alt+down", "shift-ctrl-d"], "command": "run_macro_file", "args": {"file": "Packages/User/Duplicate Lines.sublime-macro"} },

Adding another version that does the ctrl-alt-up version of the shortcut is a bit fiddle because, by default, it only swaps the selected lines one line, up, not n times where n is the number of lines duplicated