63

Is it possible to got to PHP method declaration through method call in Sublime Text?

// pressing some keys combination should navigate me
// to the method declaration. If it's defined in some other file,
// the file should be opened.
$foo->doSomething();
Roman Newaza
  • 11,405
  • 11
  • 58
  • 89

5 Answers5

111

Sublime 3 is the answer! It has a goto_definition function build in which works fine as long as you have a project with your source folder added (so that they can get indexed). I use it with scala+lift, PHP, Python.

Per default it is bound to F12 and without project setup it searches only in the actual file.

It was the missing feature to leave Eclipse and Netbeans.

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
Erik255
  • 1,463
  • 1
  • 11
  • 13
  • 2
    how do you mean *as long as you have your source folder added*? I'm working on a javascript project that uses mapbox, which in turn uses [leaflet](http://leafletjs.com/).. if i were to download leaflet where do i put it to jump to the leaflet method definitions? – abbood Feb 28 '14 at 13:03
  • 4
    `File` -> `Open Folder` and open your code root folder. Everything inside will be indexed. – Erik255 Mar 01 '14 at 10:42
  • 2
    `File` -> `Open Folder` is not an option under OSX ST3 (at least in build 3059) – watsonic Jun 19 '14 at 04:39
  • 1
    @watsonic You can just select a folder in the standard open dialog. – Nuri Hodges Jul 30 '14 at 19:42
  • 1
    you can also simply drag & drop your folder inside sublime and it will be opened in the same way – Max Sep 22 '15 at 10:54
  • How to bound this functionality to `CTRL+LMB`? I like to jump by clicking symbols in code when I get along with libraries I downloaded. – Marecky Jan 12 '18 at 12:43
  • Goto definition does not even work within the same php file. Maybe ST3 does not like PHP? – Tigerware Aug 06 '19 at 17:14
109

Update (June 2016): @Erik255's answer is better now that Sublime Text 3 is out. Please upvote his. Since this is currently the accepted answer, these are the steps repeated:

  1. Use "File > Open Folder" or "Project > Add folder to project" (you may need to create a project first)
  2. F12 will jump to any symbol in the project

Original answer:

As of Sublime Text 2, you can use Goto anything (CTRL+R).

(searches only within the current page)


codewario
  • 19,553
  • 20
  • 90
  • 159
Jay
  • 3,285
  • 1
  • 20
  • 19
  • 1
    Did you mean sublime text 3? This doesn't seem to work in my sublime? – Abe Petrillo Sep 18 '13 at 10:30
  • 14
    It does not seem to work to look for definitions of methods from other files in the same project folder, only from the same file. – ogrisel Jan 19 '14 at 15:42
  • This doesn't work for me either. [The other answer by @ogrisel](http://stackoverflow.com/a/21218979/434961) seems to be a working solution. – Batandwa Jul 20 '14 at 08:29
  • 2
    Actually Go To Anything is Ctrl-P, which is supposed to search across files, but doesn't seem to work for me. Ctrl-R is Go To Symbol, which I find more useful for finding functions/declarations within the current file. – Puneet Lamba Nov 08 '14 at 13:52
  • You need to type in the function name after the @ symbol and it will work. Don't delete the @ symbol when the dialog pops up after Ctrl + R – Bharat Apr 27 '15 at 03:24
  • 2
    After using [F12] to jump to the symbol, you can use [Alt]+[-] to go back. – Alain ANDRE Mar 02 '18 at 14:52
  • Yep - `Alt`+`-` is great because it jumps to your previous cursor position regardless of how you got there. – Jay Mar 02 '18 at 21:11
14

There is a CTags package for Sublime Text that makes it possible to use a project level .ctags .tags index file to jump to the definition of the symbol under the cursor by hitting ctrl+t twice: https://github.com/SublimeText/CTags

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
ogrisel
  • 39,309
  • 12
  • 116
  • 125
  • Please note that Sublime Text's Ctags plugin wants the file to be called **.tags** by default, but this can be altered in the plugin settings – Batandwa Jul 20 '14 at 08:35
3

There is a great plugin called SublimeCodeIntel with the following features:

  • Jump to Symbol Definition - Jump to the file and line of the definition of a symbol.
  • Imports autocomplete - Shows autocomplete with the available modules/symbols in real time.
  • Function Call tooltips - Displays information in the status bar about the working function.
Andreas Haferburg
  • 5,189
  • 3
  • 37
  • 63
sanjith edward
  • 358
  • 4
  • 12
1

For Python,

I added the project to sublime.

I press CTRL+R and then start typing the name of my function. The cursor then points to the beginning of function definition.

Hope this helps.

Swapnil B.
  • 729
  • 1
  • 8
  • 23