Navigating through selected text instances in Sublime Text 3

Ryan Urie‘s answer on StackOverflow has finally solved my little, but annoying struggle with Sublime Text 3’s key bindings (keyboard shortcuts) for navigating through all instances of currently selected text.

But that wasn’t enough for me! :>

Since ST3 is sometimes used by non-developers then these people my not catch up, how extremely important (to developer) is to be able to select addForeignKey method for example and to navigate through every existing instance of the same method call in entire file with simple keyboard shortcuts. This problem isn’t covered by default setting of Sublime Text 3 keyboard shortcuts and I had to deal with this myself.

Here is the ultimate solution to this problem. Quick and easy, as everything in Sublime Text.

To add these key bindings, you need to, as usually, open Sublime Text > Preferences > Key Bindings User and paste this in the end (or anywhere else):

 * Navigate cursor to the next (Alt+Down) or previous (Alt+Up) instance (copy)
 * of selected text.
{ "keys": ["alt+down"], "command": "find_under" },
{ "keys": ["alt+up"], "command": "find_under_prev" },

To make the whole picture, I must remind you, that this solution works only, when selection is made by double clicking a word. Only then Sublime Text is showing all instances of selected text.

Save key binding file and check (even without restarting ST3), how does it work. Double click any word to select it. Sublime Text 3 will draw an outline border around each other instance of selected text. You can now navigate through them, by pressing Alt + Up or Alt + Down.

This is just a bit better and faster solution, than the one, that I was using previously:

{ "keys": ["alt+up"], "command": "find_prev" },
{ "keys": ["alt+down"], "command": "find_next" },

In this one you have to press Ctrl + F to open search box, before you can navigate between instances of selected text. The “better” solution, given above, reduces just this one step — allows to navigate through all instances of selected text without opening search box.

Leave a Reply