Skip to main content

Featured

Ruby Tips - How to figure out where a method is defined

The other day when I was dabbling with the huge codebase, I was wondering where a particular method was being declared for a specific method. I wanted to know this because my greps didn't turn out to volatile and didn't return any results



The Solution The Ruby interpreter has certain methods that can be used for identifying under which module or class, the particular method is being defined. See the example below.

So using the .source_location you will be able to figure which file it has been declared.

Sublime 2 Keyboard Shortcuts

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+Ccopy current line (if no selection)
Ctrl+Xcut current line (if no selection)
Ctrl+⇧+Kdelete line
Ctrl+↩insert line after
Ctrl+⇧+↩insert line before
Ctrl+⇧+↑move line (or selection) up
Ctrl+Lselect line (repeat to select next lines)
Ctrl+Dselect word (repeat select others occurrences in context for multiple editing)
Ctrl+Mjump to closing bracket for current code, repeat to jump to opening bracket
Ctrl+⇧+Mselect all contents of the current brackets (curly brackets, square brackets, parentheses)
Ctrl+KKdelete from cursor to end of line
Ctrl+K+⌫delete from cursor to start of line
Ctrl+]indent current line(s)
Ctrl+[un-indent current line(s)
Ctrl+⇧+Dduplicate line(s)
Ctrl+Jjoin line below to the end of the current line
Ctrl+ /comment/un-comment current line
Ctrl+⇧+/block comment current selection
Ctrl+Yredo, or repeat last keyboard shortcut command
Ctrl+⇧+Vpaste and indent correctly
Ctrl+Spaceselect next auto-complete suggestion
Ctrl+Usoft undo (somehow undoes your movements; it jumps to your last change before undoing it when you repeat this command)

Navigation/Goto Anywhere

Ctrl+Pquick-open files by name in your project (doesn’t seem to need an actual project set up, it just searches in the directories around the currently-opened file
Ctrl+Rgoto symbol (functions and classes) in the file. Same as Ctrl+P, then type @
Ctrl+;goto word in current file. Same as Ctrl+P, then type #
Ctrl+Ggoto line in current file. Same as Ctrl+P, then type :

General

Ctrl+⇧+Pcommand prompt
Ctrl+KBtoggle side bar

Find/Replace

Ctrl+Ffind
Ctrl+Hreplace
Ctrl+⇧+Ffind in files

Tabs

Ctrl+⇧+topen last closed tab (just like in your browser)
Ctrl+PgDncycle down through open tabs, cycle up with Ctrl+PgUp
Ctrl+⇆cycle through last tabs (repeat to go back further in history)

Split window

Alt+⇧+2split into two columns
Alt+⇧+1revert to single column
Alt+⇧+5grid (4 groups)
Ctrl+[1,2,3,4]jump to “group” (pane)
Ctrl+⇧+[1,2,3,4]move file to specified group

Bookmarks

Ctrl+F2toggle bookmark
F2next bookmark
⇧+F2previous bookmark
Ctrl+⇧+F2clear bookmarks

Text manipulation

Ctrl+KUupper case
Ctrl+KLlower case

Comments

ananth said…
Sublime has changed a lot. But some keyword combination brought me here. kudos.

Popular Posts

You will receive wonderful short stories written by him and inspirational articles once every month.