Useful keyboard shortcuts in Sublime Text 3
This is one of the last article in my private serie of blog entries targeting developers, who starts their journey with Sublime Text 3. Treat it as memo or list for easy remembering sometimes very useful, not always often, keyboard shortcuts, that are available in ST3. Where it is possible, I’m adding links to Sublime Text Unofficial Documentation, which is great source of information in any aspect related to Sublime Text 3.
Note, that entire document is based on default Sublime Text 3 key bindings, before any user changes, like for example those mentioned in [Netbeans-like keyboard shortcuts in Text 3.txt] text. Also note, that when speaking about Alt key, I’m referring to left key. As on some non-English keyboards, right Alt key may have different meaning (entering language-specific letters etc.).
Multiple cursors and selections
Sublime Text 3 allows you to edit text in more than one place at once, using multiple cursors. Simply hold Ctrl key, click in two or more places to set multi cursors. Then start typing anything and observe the effect of text being entered in all these positions simultaneously. Click anywhere without Ctrl pressed to “reset” back to one cursor mode.
You can also use multiple selections. Select some text and press Ctrl+D to select next instance of the very same text, as in current selection. Continue pressing Ctrl+D to move forward and select following instances of selected text. Press Ctrl+U to move backward, unselecting each previously selected instance. Press Ctrl+K and Ctrl+D to skip current instance and move to the next one.
If you wish to select entire line, press Ctrl+L.
There are few useful keyboard shortcuts for quick selection expanding. Ctrl+Shift+Right or Ctrl+Shift+Left traditionally (as in many editors) spans selection over next or previous word. Alt+Shift+Right and Alt+Shift+Left does the same, but they operate of “subwords”, which means — will stop also on underscore (_), which is very useful for selecting variables, symbols etc. Previous set of shortcuts stops only on spaces, so in the word this_is_an_example it will expand selection for the entire word at once, while Alt+Shift and arrows will expand on each of these “subwords” respectfully.
Pressing Ctrl+Shift+M will select entire text inside current brackets. Used mostly, when cursor stands next to the opening bracket, to expand selection all the way to the closing bracket. But, can be used also in any place between two brackets.
Ctrl+T is used by default for transposing (swapping together) two letters or two words. But, if you installed CTags plugin (more about in this article, then this shortcut will be overridden by that plugin for its base functionality. You must define your own for transposing or redefine CTags’s shortcut to use these two functionalities together. Read [Netbeans-like keyboard shortcuts in Text 3.txt] to find out more about key bindings in Sublime Text 3 and for examples of user-defined keyboard shortcuts.
Searching and replacing
When search box (Ctrl+F) is opened, you can use both F3 and Enter to move to the next search result (found text instance) and both Shift+F3 and Shift+Enter to move back to previous one. If search box is hidden, but search query defined, you can use only F3 / Shift+F3 shortcuts. With the same logic, you can use both Alt+F3 and Alt+Enter to select all instances matching current search criteria, when search box is open, or only first one, if it is closed.
You can use Ctrl+Shift+H to replace currently selected instance of search criteria with given replace pattern and move and select following one (if nothing is selected, it selects nearest instance, but not replaces anything with first pressing of this shortcut). You can also use Ctrl+Alt+Enter to replace all instances at once. These two shortcuts works no matter, if replace box (Ctrl+H) is open or closed.
Hit Esc to dismiss both search and replace pane.
Press Ctrl+0 to focus sidebar, to be able to use it (navigate through files and folder) with just your keyboard. Hit Esc to go back to the editor.