Wednesday, December 30, 2015

Multi-select (multi-cursor) functionality in the Atom Editor

If you've used Sublime Text, you may have become familiar with the neat multi-selection/multi-cursor functionality that you can use.  
Recently, I've started using the Atom Editor, and I wanted similar functionality to quickly select multiple lines of text and do the same action on all of them.
Apparently, there is some built-in multi-cursor functionality in Atom, but it's mouse-only.  You have to Ctrl-Click each place you want to put a cursor.
Luckily, Atom is extendable with open source packages, and I was able to find multi-cursor, which did almost everything I wanted.
The original directions for updating the keymap were incorrect, so it didn't function for me until I updated it to this.
'atom-workspace atom-text-editor:not([mini])':
  # Expand current cursor
  'ctrl-down': 'multi-cursor:expandDown'
  'ctrl-up':   'multi-cursor:expandUp'
Warning: Ctrl-Alt-(Up/Down/Left/Right) can be the default hotkeys of changing your screen's orientation in Windows, so unless you want to do that, update the atom keybinding to something else or remove those hotkeys from the graphics settings.
Luckily, this code is open-source, so I opened up a pull request on Github to fix the documentation to reflect how it worked for me.
The correct syntax for the keybinding you want to change in Atom can be obtained by going to "Settings" -> "Keybindings".

  • Search for the keybinding that you're having issues with (like ctrl-down), and click the clipboard icon next to the keystroke.
  • Paste that syntax into the keymap.cson file and edit as necessary.