One of the best features in Sublime Text is the way it makes it simple to open file and find specific pieces of code inside your project. In this article we’ll discuss how to use some of the Goto menu items.
The Goto Anything option (command+P or ctrl+P) is the quick way to open any file that exists in the directory/project that you’re working in. When you first open the Goto Anything command palette it will present a list of recently opened files and you can start typing to have it start listing options for what you want to open.
When you’ve gotten what you want selected you can hit enter and the file will be opened.
My hope is that if you’ve gotten anything out of this series it’s using command+P or ctrl+P and opening files this way instead of using the Side Bar. The Side Bar is helpful if you’ve forgotten the name of the file but this is much faster.
Goto Symbol (command+R or ctrl+R) provides a quick way to jump to a specific symbol in a file. Depending on the type of file it will show different Symbols but it usually picks out the major items.
PHP shows the class name and functions:
CSS shows the various selectors:
Markdown even finds the headings:
Using Goto Anything
If you noticed in our screenshots above when you try to the Goto Symbol the Goto Anything box is shown with at sign (@) as the first character. The trick is that you can open the Goto Anything input and type the at sign (@) as the first character. For me, it’s easier to remember this than it is to train my hands to do command+R.
Goto Symbol in Project
Goto Symbol in Project (command+shift+R or ctrl+shift+R) allows you to find a function or class across all the files in your project. Typing the name of a function and hitting enter will bring you directly to the file and functions that you need:
Unless there are multiple files that match that symbol in which case you’ll be presented with a list of files that match.
The Goto Line (ctrl+G) allows you to quickly jump to a line in the file. This is helpful if you get an error message like so:
You can easily hit ctrl+G and type “11” and enter to get you right to that line.
Using Goto Anything
In our screenshots above you might be able to see that when we do the Goto Line the Goto Anything box is shown with a colon (:) as the first character. Like the Goto Symbol trick above, you can open the Goto Anything input and type colon as the first character to perform the same.
Goto Line in a Different File
The only downside (if you can call it a downside) to Goto Line is that it really only works well inside the same file. However the Goto Anything input can help us. If we enter the name of the file then a colon it will take us directly to that line in that file. In the message above we can copy and paste “WebsiteBundle/Tests/Controller/DefaultControllerTest.php:11” into the Goto Anything input and it will take us directly to the offending line.