Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to jump to source code of a method in Sublime Text with key binding?

In Sublime Text editor, you can type COMMAND+P to search for other files based on file names (fuzzy match greatly speeds up this process).

For example, if you see the following code in one source file (example in Ruby):

u = User.new
u.send_email

and you want to see the definition of User class, you can type COMMAND+P and enter "User" to see a list of candidate files (whose names contain "user") you can open to view.

Is it possible to jump to the source code of User class without typing "User"?

As you navigate in the source code, your cursor is on User.new or u.send_email, it would be much faster if you can use some key-binding to jump to the file that contains the definition of either User class or the send_email method.

Is this supported by Sublime Text or any of its wonderful plugins?

Thank you.

like image 444
Zack Xu Avatar asked Feb 21 '14 12:02

Zack Xu


People also ask

How do I run the source code in Sublime Text?

To run code in Sublime Text, go to Tools > Build System, and select the language for your code (Sublime comes with support for various languages like Python, Ruby, Bash, and more). Next, press Cmd+B on Mac or Ctrl+B on Windows to run your code.

How do I change key bindings in Sublime Text?

Users can customize their key bindings by creating a file named Default. sublime-keymap in their Packages/User/ directory. For example, the following will create a key binding to show unsaved changes, if any exist, via Ctrl+Shift+`.

How do I search a line in Sublime Text?

In Sublime Text, you can quickly jump to any line in the code. Hit Ctrl–G (Mac and Windows). Type in a line number and hit Return/Enter to go to that line.

How do you comment a block of code in Sublime Text?

The shortcut to comment out or uncomment the selected text or current line: Windows: Ctrl + / Mac: Command ⌘ + / Linux: Ctrl + Shift + /


2 Answers

A great way to do this is to install CTags.

Then you simply put your cursor over the class or method of interest:

enter image description here

Then press ctrl+t, ctrl+t and it will jump to the location of that class or method's definition:

enter image description here

like image 183
AGS Avatar answered Oct 13 '22 01:10

AGS


You can use:

-Bookmarks: CTR + F2 to add, and F2 to go next bookmark

-Go to a method with CTRL +R in the active tab.

-'Jump to Symbol Definition' with a context menu with SublimeCodeIntel.

-You can try with Find Function Definition, but it isn't entirely effective.

like image 41
MaicolBen Avatar answered Oct 13 '22 00:10

MaicolBen