Sublime Forum

Column selection

#1

Hi,

i would like to see a column selection mode :wink:.

0 Likes

#2

You can drag with the middle mouse button (generally the mouse wheel), or shift+right mouse button to do a column selection.

0 Likes

#3

Ah, didn’t try that, thanks.

[size=75]although it would be nice if this could be trigged via keyboard only too (alt+ up/down/left/right?)[/size]

0 Likes

#4

another thing:

when i have something like this

foo foo bar bar
foo foo bar bar

foo foo bar bar
foo foo bar bar

foo foo bar bar
foo foo bar bar

foo foo bar bar
foo foo bar bar

and want to replace/select the first “bar” i get this

foo foo |bar| bar
foo foo |bar| bar
|
foo foo |bar| bar
foo foo |bar| bar
|
foo foo |bar| bar
foo foo |bar| bar
|
foo foo |bar| bar
foo foo |bar| bar

Imho it would be nice if empty parts would be ignored when selecting columns, so only the bars would be selected.

0 Likes

#5

Sometimes you want the column selection to select empty areas, such as dragging to the right of the text to quickly get one cursor per line.

I’ll take a look at changing the behaviour so that all the empty regions are removed as soon as there’s at least one non-empty region in the column selection.

0 Likes

#6

I’m new to Sublime so I’m not sure if this is already possible, but it would be really useful to be able to do column mode selection from the keyboard - maybe alt+arrows, rather than the normal shift+arrows - does anyone know if you can do this now, or if it’s planned for the future?

0 Likes

#7

Welcome to the forums! There’s no way to do it yet, but I’ll add something for the next beta.

0 Likes

#8

Any update on binding column selection to keyboard shortcut?

0 Likes

#9

Still only half way there: As Sublimator mentioned, Ctrl+alt+up/down implements a sort-of column select.

0 Likes

#10

…and finish with shift to do the actual selection.
it’s good enough, thanks

0 Likes

#11

And if, like me, you need to cut & paste some columns using the keyboard, here’s a simple plugin to do it:

import sublime, sublimeplugin

class pasteColumnCommand(sublimeplugin.TextCommand):
	def run(self, view, args):
		clip = sublime.getClipboard().split(u"\n")
		for region in view.sel():
			view.replace(region, clip.pop(0))

	def isEnabled(self, view, args):
		return sublime.getClipboard() != ""
0 Likes

#12

delicious! i was missing this kind of ability :smile:

0 Likes

#13

Column selection and replace works amazing, but it is only for rectangular selection
e.g. replacing - with _ in the name attribute without touching the other -

<string name="x-x-x">a-a-a</string>
<string name="y-y-y">b-b-b</string>
<string name="z-z-z">c-c-c</string>

I have tried other editors as well and then replace in the column selection was not possible (selection disabled or all lines were selected)

But what if it looks like:

<string name="x-x">a-a-a</string>
<string name="y-y-y-y-y">b-b-b</string>
<string name="z-z-z">c-c-c</string>

What I would like is an organically adjusting selection. You select x-x and then like column selection it auto adjusts the selection upto the double quotes. It looks constantly for the same shape in every line and add it to the selection.
I don’t know if this already possible in Sublime Text by the way or what the real name for it is ( “organic block selection”, “column selection with Gaudí feature”,“shape based selection”, “auto regexp selection” :wink: ).

0 Likes

#14

There are different ways to do this with multiple selections in Sublime. On approach is to use whole-word navigation (ctrl+shift+arrow_keys) once you have the cursors at the beginning (or end) of your desired text. shift+home/end are also very helpful. I’m almost always able to fulfill my oddly-shaped selection criteria using that approach. In the few cases where that approach hasn’t worked, you can always do a regular expression search.

In your example, you could easily get your desired multiple selections in the following way:

  1. select all of the end of the name attribute values: closing quote with closing angle bracket (">)
  2. extend the selections to the beginning of the line with shift+home
  3. deselect to the beginning of the name attribute value with 3 times ctrl+shift+right_arrow.
0 Likes