nelsonic
nelsonic

Reputation: 33134

Is there a keyboard shortcut to select a column for editing in Atom editor?

Scenario

When editing a file in Atom Editor how do I select multiple lines where the same edit needs to be performed?

For example:

this.name  = name;
this.age   = age;
this.sound = sound;

needs to be transformed into:

that.name  = name;
that.age   = age;
that.sound = sound;

Imagine there are many of these lines, but we do not want to use a find-and-replace because it will change more than we need.

Question - Is there a Keyboard Shortcut for Column Selection?

Is there a sequence of keyboard shortcuts (preferably Mac) which we can use to:

then apply the change to several lines at once (in bulk)

I know how to do this in SublimeText: http://sublime-text-unofficial-documentation.readthedocs.org/en/latest/editing/editing.html#column-selection but have tried many different key combinations without any luck in Atom and googling has proved fruitless...

Upvotes: 45

Views: 48732

Answers (7)

JavaTec
JavaTec

Reputation: 1044

On Windows 10, follow the following steps:

  1. Press ctrl + alt together and use up/down arrow keys to expand the height of your now vertical cursor
  2. Now use shift to select the columns to be deleted
  3. press delete key to remove selected columns
  4. click anywhere on document (without pressing ctrl/alt keys) to bring cursor back to normal 1 column height

Upvotes: 2

Olshansky
Olshansky

Reputation: 6404

I've tried all of the following potential solutions:

  1. sublime-style-column-selection
  2. multi-cursor
  3. multi-cursor-plus
  4. Adding the following text to /Users/$(whoami)/.atom/leymap.cson
'atom-workspace atom-text-editor:not([mini])':
  'alt-down': 'editor:add-selection-below'
  'alt-up': 'editor:add-selection-above'

The last solution is the one that worked best without interfering with any of my other normal workflows.

Upvotes: 0

Olshansky
Olshansky

Reputation: 6404

I came by this thread, and the feature I was personally looking for was the multi-cursor extension.

Upvotes: 0

user3668158
user3668158

Reputation: 171

With the cursor somewhere on the first "this", do Ctrl+D (OS X: command+D) three times. Then type "that".

Another option is to select the rows you want to edit. Then select "Split into Lines" from the "selection" menu. Then hit the home-key and start editing away in multi-cursor mode.

Upvotes: 13

Vineel
Vineel

Reputation: 1440

For me on Atom 1.7.4 it worked by adding below lines to my /Users/username/.atom/keymap.cson. Ofcourse I am using alt-shift-down as shortcuts.

'atom-workspace atom-text-editor:not([mini])':
  'alt-shift-down': 'editor:add-selection-below'

Update: I could not configure both alt+shift+down and alt+shift+up at the same time. For now I am okay with alt+shift+down

Upvotes: 10

Michael Gomes
Michael Gomes

Reputation: 176

Here is a plugin for Atom, just hold alt and be happy. sublime-style-column-selection

Upvotes: 14

nwinkler
nwinkler

Reputation: 54437

There are several ways to achieve this:

Keyboard

You can enable column selection mode using Ctrl+Shift+↑/↓. This will allow you to extend the cursor to multiple rows. Once you have selected all rows, release the keys, and use the Delete key to remove the text you want to replace. Once you're done, press the Esc key to release the cursors.

Note: You will have to disable the Mission Control (key bindings) in OS X to use this key combo.

How to Disable Mission Control (conflicting) Key Bindings (Mac)

To do this open System Preferences > Mission Control

enter image description here

Locate the key bindings for Mission Control and Applications windows:

mission-control-key-bindings

Disable the key bindings for these two:

enter image description here

More details here.

Mouse

If you install the Sublime Style Column Selection package, you can use Alt+Mouse to select the columns in question.

More details here.

Upvotes: 61

Related Questions