One of the features I miss from TextMate is the ability to convert a multi-line selection into a column selection by simply tapping on the ⌥ (Option/Alt) key. 99% of the time I used this create multiple cursors without anything selected. The following animated GIF should explain what I mean. I’m using the keyboard to select multiple lines and then I tap ⌥ to convert my selection into a bunch of cursors stacked on top of each other.
Both Atom and Sublime have a command to convert a selection into multiple lines “Selection > Split into Lines” and it’s mapped to ⇧⌘L by default. This almost does what I want. It gives me multiple selections, but it doesn’t give me a nice stack of cursors the way TextMate does.
To get the same thing TextMate gives me with a simple tap of the ⌥ key, I have to hit:
- ⇧⌘L
- ⌘→
- ⌘←
Yes, I could just hold ⇧⌃ and tap the up or down arrows to create a stack of cursors right where I want them. And there are still times when I do this in Atom or Sublime. I have two issues with creating the column of cursors this way: First, my muscle memory is wired to make a selection first and then convert to cursors or selections. Secondly, the ⇧⌃↓ method is less forgiving; if you overshoot, you have to start the process over over.
Okay, so let’s try to get that TextMate-style behavior working in Atom or Sublime.
First, grab a copy of Karabiner and install it. Karabiner will allow us to remap a single tap of the Option key to a sequence of keyboard commands while in Atom or Sublime. Karabiner has tons of other features that I’m not going to mention here. At the very least, you should look into using it to set up a Hyper Key on your Mac.
In Karabiner, do the following:
- In the
Misc & Uninstall
tab, hit theOpen private.xml
button. -
That will open a Finder window with the
private.xml
so you can easily open it in your text editor. -
If you’re using Atom, enter the following
<item>
node within the<root>
:<item> <name>Tap left Option to convert selection to multiple cursors in Atom</name> <identifier>private.lo_cursors.atom</identifier> <only>Atom</only> <autogen> --KeyOverlaidModifier-- KeyCode::OPTION_L, ModifierFlag::OPTION_L, KeyCode::OPTION_L, KeyCode::L, ModifierFlag::COMMAND_L | ModifierFlag::SHIFT_L, KeyCode::CURSOR_RIGHT, ModifierFlag::COMMAND_L, KeyCode::CURSOR_LEFT, ModifierFlag::COMMAND_L </autogen> </item>
For Sublime, the important difference is the
<only>
node:<item> <name>Tap left Option to convert selection to multiple cursors in Sublime</name> <identifier>private.lo_cursors.sublime</identifier> <only>SUBLIME TEXT</only> <autogen> --KeyOverlaidModifier-- KeyCode::OPTION_L, ModifierFlag::OPTION_L, KeyCode::OPTION_L, KeyCode::L, ModifierFlag::COMMAND_L | ModifierFlag::SHIFT_L, KeyCode::CURSOR_RIGHT, ModifierFlag::COMMAND_L, KeyCode::CURSOR_LEFT, ModifierFlag::COMMAND_L </autogen> </item>
- Save
private.xml
. Back in Karabiner, in theChange Key
tab, hit theReload XML
button. -
Finally, in
Karabiner
, make sure your new option, either “Tap left Option to convert selection to multiple cursors in Atom” or “Tap left Option to convert selection to multiple cursors in Sublime”, is checked.
This works the way I want it to. Most of the time. There are times when I want to create a column of stacked cursors in the middle of lines of text. In that case, this hack doesn’t work because the column of cursors always ends up at the start of the lines. Totally copying the TextMate behavior might be possible with a custom Atom plugin.