Dev Hack: Vertical Selection in Sublime Text 2 on Mac
posted by Dom Benoscek
on Dec 22, 2013
Coming from the Windows world I had grown accustomed to using Notepad++ for all of my text editing needs. While there are many great text editors for Windows, Notepad++ is my favorite as it offers many features in a clean, easy-to-use, interface. What’s more, it does one thing really well: vertical selection. I don’t use this functionality all of the time but, as a strong proponent of well-formed code, when I need to adjust the horizontal spacing of numerous lines at once, this functionality is a huge time saver.
Now that I spend most of my time on a Mac, I have been in search of an equivalent text editor. Many great editors exist but I have landed on Sublime Text 2 for its developer-friendly editing window and the large selection of plugins that are available. So far, Sublime Text 2 has lived up to the hype except for one important piece of functionality: vertical selection.
The good news is that Sublime Text 2 supports vertical selection. The bad news is that my keyboard configuration did not allow me to use it. All is not lost though, Sublime Text 2 allows you to edit the keyboard shortcuts that trigger vertical selection. The tricky part is figuring out where and how to update these shortcuts.
First, navigate to Sublime Text 2 >> Preferences >> Key Bindings – Default. The syntax of this file will likely look familiar to you because Sublime Text 2 stores its keyboard shortcuts as a JSON object. Locate the lines that read as follows:
In my particular file, the corresponding text was found at line numbers 45 and 46, respectively. Once located, copy these two lines and navigate to Sublime Text 2 >> Preferences >> Key Bindings – User. The next steps are to paste the copied text into the Key Bindings – User file, modify the corresponding keyboard shortcuts, and to verify the Key Bindings – User file contains a properly formatted JSON object.
For my particular configuration I choose to change the “ctrl+shift+up” and “ctrl+shift+down” shortcuts to “command+shift+up” and “command+shift+down”. You can use whichever shortcuts you like but I recommend verifying that the shortcuts you choose don’t override other useful shortcuts. After updating the code, verify that your file looks similar to the following:
You can also verify whether you have a valid JSON object by pasting your object into the JSONLint JSON validator.
After saving the Key Bindings – User file, the updated keyboard shortcuts will be instantly available. Open up/navigate to a text file and press the shortcuts (in my example “command+shift+up” or “command+shift+down”) to start selecting vertically.