Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Atom Editor - How to select rectangle with multi cursor

Tags:

atom-editor

I have liked a feature very much in Notepad++, pressing Alt and selecting with the mouse enabled a rectangular selection, just like the selection on desktop...can not think of a proper term for it, maybe rectangular selection or vertical selection or block selection. The cool thing was that it worked also with blank line endings, it generated spaces automatically.

Is there a similar functionality in Atom?

So for example, an use case would be to extract a list of files with tree command :

.
├── element_portals_commands
│   ├── depends.txt
│   └── init.lua
├── element_portals_functional
│   ├── portal_data_api.lua
├── liquid_portals
│   ├── constants.lua
│   ├── crafts.lua
│   ├── depends.txt
│   ├── sounds
│   │   └── fireball_whoosh.ogg
│   └── textures
│       ├── ray_y_tile.png
│       └── README.md
.......

place the multi cursor at a fixed width (the last | for each line represents the cursor)

.                                       |
├── element_portals_commands            |
│   ├── depends.txt                     |
│   └── init.lua                        |
................
│   ├── sounds                          |
│   │   └── fireball_whoosh.ogg         |
│   └── textures                        |
│       ├── ray_y_tile.png              |
│       └── README.md                   |
.......

and start typing

.                                       <- |
├── element_portals_commands            <- |
│   ├── depends.txt                     <- |
│   └── init.lua                        <- |
................
│   ├── sounds                          <- |
│   │   └── fireball_whoosh.ogg         <- |
│   └── textures                        <- |
│       ├── ray_y_tile.png              <- |
│       └── README.md                   <- |
.......

What I do now to achive this:

  1. Find and replace the end of line \r or \n with a lot of spaces &nbsp;&nbsp;&nbsp;\n
  2. Then Ctrl + Click my way out.
  3. Insert a char.
  4. Trim the end of the line.

I'm sure there is a better way. It is possible without any plugin? Do you know an alternative?

Update :

Some further research showed that

Add selection below alt+shift+

places another cursor beneath the current cursor... but it doesn't pad the lines with white spaces. Exists something that also pads the lines ?

like image 521
Tiberiu C. Avatar asked Sep 27 '15 22:09

Tiberiu C.


People also ask

How do I select multiple cursors in an atom?

the default keybindings Ctrl+Shift+Up/Down seems to work. Then place the cursor where you want to start and press and hold Shift+Alt and press Up or Down repeatedly to extend the cursor to as many lines as needed.

How do you select vertically in an atom?

Hold the modifier key then click and drag with the configured mouse button across multiple lines. Dragging vertically places carets on each line at that column; dragging horizontally as well selects the text on each line.

How do you select a block of code atom?

Ctrl+Alt+M ( Cmd+Ctrl+M on Mac) selects entire code inside the current brackets.


2 Answers

First, according to the official site of Notepad++, this function is called column mode editing.

There is a plugin to do similar thing in Atom, but sadly it will just skip lines if that line is not long enough, instaed of filling space. This is the plugin:

Sublime-style-column-select

like image 142
cytsunny Avatar answered Sep 19 '22 00:09

cytsunny


Today I found a package in Atom named "column-select". So far it works perfectly fine. They way it works is very close to the implementation of Block selection of Rstudio and Kate.

It does not add space to fill the gap. It literally let you select vertically if there is anything there (skips empty lines and lines that does not have enough length).

The following gif from their github shows how it works:

enter image description here

like image 42
Mehrad Mahmoudian Avatar answered Sep 20 '22 00:09

Mehrad Mahmoudian