72
votes

I'm on a Mac. I have 7 columns in Sublime Text 3, each 300 lines each. If possible, I would like to select only the 4th column using a single keyboard shortcut.

Unsuitable options

  • ctrl + shift + up/down
  • alt + mouse + drag
  • ctrl + alt + up/down. (This actually doesn't do anything, nor does it appear in my console session and nor is it a single keyboard shortcut).
  • I'd also prefer not to use VI/VIM mode just for this as it's not regular part of my workflow

What I've tried:

  • A macro: but it isn't specific enough.
  • using command and 'page down' with ctrl and 'shift`: no luck
  • SublimeText 3 Column-Select plugin: did not seem to work for me

My ideal solution would be that my cursor could be placed anywhere in a column and I would hit a shortcut (e.g. ctrl-alt-shift-a) and it would select the whole column.

Here is an example:

John Sally Benson Mariah Patrick Samantha Martin

Simon Kate Carey Delores Joshua Samuel Eliza

I want to select the column with Maria and Delores with one keystroke. I perform this action often so for various reasons (cut/paste, change case, append, add quotes, run macro etc) and thus would want something quick and repeatable.

How would I do this?

9
I couldn't find a satisfactory answer in this thread. I did find one here though: stackoverflow.com/questions/10080202/…marvin

9 Answers

160
votes

You should see Sublime Column Selection:

Using the Mouse

Different mouse buttons are used on each platform:

OS X

  • Left Mouse Button +
  • OR: Middle Mouse Button

  • Add to selection:

  • Subtract from selection: +

Windows

  • Right Mouse Button + Shift
  • OR: Middle Mouse Button

  • Add to selection: Ctrl

  • Subtract from selection: Alt

Linux

  • Right Mouse Button + Shift

  • Add to selection: Ctrl

  • Subtract from selection: Alt

Using the Keyboard

OS X

  • Ctrl + Shift +
  • Ctrl + Shift +

Windows

  • Ctrl + Alt +
  • Ctrl + Alt +

Linux

  • Ctrl + Alt +
  • Ctrl + Alt +
25
votes

The reason why the sublime documented shortcuts for Mac does not work are they are linked to the shortcuts of other Mac functionalities such as Mission Control, Application Windows, etc. Solution: Go to System Preferences -> Keyboard -> Shortcuts and then un-check the options for Mission Control and Application Windows. Now try "Control + Shift [+ Arrow keys]" for selecting the required text and then move the cursor to the required location without any mouse click, so that the selection can be pasted with the correct indentation at the required location.

14
votes

In my case (Linux) is alt+shift up/down

 { "keys": ["alt+shift+up"], "command": "select_lines", "args": {"forward": false} },
 { "keys": ["alt+shift+down"], "command": "select_lines", "args": {"forward": true} },    
8
votes

The SublimeText 3 Column-Select plugin should be all you need. Install that, then make sure you have something like the following in your 'Default (OSX).sublime-keymap' file:

    // Column mode
    { "keys": ["ctrl+alt+up"], "command": "column_select", "args": {"by": "lines", "forward": false}},
    { "keys": ["ctrl+alt+down"], "command": "column_select", "args": {"by": "lines", "forward": true}},
    { "keys": ["ctrl+alt+pageup"], "command": "column_select", "args": {"by": "pages", "forward": false}},
    { "keys": ["ctrl+alt+pagedown"], "command": "column_select", "args": {"by": "pages", "forward": true}},
    { "keys": ["ctrl+alt+home"], "command": "column_select", "args": {"by": "all", "forward": false}},
    { "keys": ["ctrl+alt+end"], "command": "column_select", "args": {"by": "all", "forward": true}}

What exactly about it did not work for you?

6
votes

This should do it:

  1. Ctrl+A - select all.
  2. Ctrl+Shift+L - split selection into lines.
  3. Then move all cursors with left/right, select with Shift+left/right. Move all cursors to start of line with Home.
3
votes

For macOS, you don't need install any plugin or mouse. just do like this :- Ctrl+Shift+Down

2
votes

Alright, here's the best solution I've found that meets all the requirements:

  1. Download the Sublime-Text-Advanced-CSV Sublime plugin and install.
  2. Specify a delimiter for your column (default is ","), via the "CSV: Set Delimiter" command.
  3. Hit "ctrl + , s" (or select from Command Palette) and your column will be selected.

No need for mouse interaction whatsoever.

0
votes

Commenting just so people can have a solution to the intended question.

You can do what you are wanting but it isn't quite as nice as Notepad++ but it may work for small solutions decently enough.

In sublime if you hold ctrl, or mac equiv., and select the word/characters you want on a single line with the mouse and still holding ctrl go to another line and select the word/characters you want on that line it will be additive and you will build your selection. I mainly use notepadd++ as my extractor and data cleanup and sublime for actual development.

The other way is if your columns are in perfect alignment you can simply middle click on windows or option + click on mac and this enables you to select text in a square like fashion, Columns, inside the lines of text.

-2
votes

I know notepad++ has a feature that lets you select blocks of text independent of line/column by holding control + alt + drag. So you can select just about any block of text you want.