Join Kevin Yank for an in-depth discussion in this video Using the Goto Anything command, part of Up and Running with Sublime Text 2.
Probably my favorite feature in Sublime Text 2 is GoTo Anything, and I've actually already showed it to you, I just didn't show you everything it could do. GoTo Anything is what you get when you hit Ctrl+P or Command+P, it's this palette that I previously said you could use to switch between open files. But now that we're working in a project, you can see that it doesn't just list the index.htm file that I have opened, but all of the files in my project, and by selecting them, I can peek at their contents without actually opening them.
I can also type a few letters like spot to jump straight to spotlight.htm and open it right away. So, a very quick file finder and opener for our projects, but we're just getting started, GoTo Anything has a few more tricks up its sleeve. If I bring it up again and hit a number sign this switches it into fuzzy matching mode, and I can do a fuzzy search by typing something like RX, and you can see it has narrowed it down to the word Roux in the file, and it highlighted it in the background.
So this is very much like an incremental search that we saw before you can quickly jump to a part in the file using the search, but it uses fuzzy matching, so I didn't have to type Roux, I could just type RX, and it knew what I was talking about. You can use this fuzzy matching in combination with the file opening feature of GoTo Anything. So, if I type Command+W or Ctrl+W to close my spotlight.htm file bring up GoTo Anything again, if I type spot and then number sign, you can see I am now doing a fuzzy search inside that spotlight.htm file, even though it's not yet open, and again if I type RX, I've found the word Roux.
I can hit Enter to open this file, or I can just hit Escape to go back to what I was doing now that I've seen what I needed to see in that file. Besides the number sign for a fuzzy match GoTo Anything has a few other tricks that it can do. First of all, you can jump to a line number, so let's say I am working in SpryTabbedPanels.js, and it's told me that I have an error on line number 50. Well, I can bring up my GoTo Anything and then just type a colon to put it in line number mode and then type 50 and hit Enter, and that drops me straight on line 50, which happens to be blank in this case, let's say it was line 49.
Once again, this can be used in combination with my file opening, I'll close down my file, again bring up GoTo Anything, and I'll type SpryTabbedPanels.js then I'll hit a colon to go to line number 49. And once again, I'm peeking at line number 49, and that file without actually opening it, and I can just hit Escape to go back to what I was doing, if I don't actually need to open the file. The last thing that go to anything can do is give you a symbol list.
If I bring up my GoTo Anything pop-up for index.htm and then put in an at sign, you can see a list of the IDs in the file pageNav, mainContent and pageFooter, and different types of files use this symbol list for different things. Let's say I was working on this header tags here, and I wanted to remind myself what the home header class, what styles this applies to this header element. Well, I can just pop up go to anything, I'll type CSS to find my CSS files, in this case it has correctly found my main.css, I'm going to then hit the at sign to go into symbol mode, and you can see a list of all of the selectors in this file.
If I type homeHeader--or in this case, all I need to type is home--I can see right away the style that is applied to the home header class, it sets a height of 388 pixels and gives it a background image. And once again, I can hit Enter to jump straight to this file and open it at that point, or I can hit Escape to go back to what I was doing in index.htm so that is GoTo Anything not only does it let you peek at an open file, it lets you do fuzzy searches with hash, it lets you jump to a line number with colon, and lets you search through the list of symbols in a file with the at sign. It's a very rich feature, and once you get used to using all of these capabilities, I think it's going to be your favorite too.
- Opening, viewing, and editing files
- Adding custom themes and color schemes
- Performing different types of find and replace operations
- Editing multiple lines simultaneously
- Automating tasks with macros and snippets
- Working with add-ons like Package Control, Line Endings, and Hyperlink Helper