Question

Is there any way to select column with keyboard shortcut and expand selection till the end of each line?

Currently, when cursor reaches the end of the line it jumps to the beginning of the next one.

How can I avoid this behavior without using mouse?

Was it helpful?

Solution

If I've understood your question correctly, you can do that with the following keys (example with OS X keybindings):

  1. Ctrl + Shift + Up or Ctrl + Shift + Down to select a column in multiple lines.
  2. Cmd + Shift + Right (Shift + End on other OS's) to extend the selection up to the end of each line.

The related keybindings for all OS's: http://www.sublimetext.com/docs/2/column_selection.html

OTHER TIPS

I came to this answer because I was searching how to place the cursor in all the lines until EOF (end of file) without using ctrl+alt+/ (not pratical for more than a few dozens of lines), so I could trim or select a specific part of those lines.

So I eventually ended up in the sublime text documentation where I found:

  • ctrl+shift+L which will place cursors in all the lines selected and at the end of them (EOL):
    • select those lines with ctrl+L (or ctrl+shift+End to select until EOF);
    • press ctrl+shift+L to add cursors at EOLs;
    • now you can move all the cursors simultaneously by words with ctrl+/ or to the BOLs/EOLs with Home/End), if you also press shift you will select while moving them;
  • but the most useful feature is definitely the middle click of the mouse + drag which selects the lines and simultaneously places cursors at the end of those selections:
    • BONUS: If you just want to place the cursors at EOLs (without selecting) click on the background (after the EOLs) and drag! (if the lines are too long you can use the minimap to position your view-screen at the longest line);
    • now you can move all the cursors simultaneously by words with ctrl+/ or to the BOLs with Home), if you also press shift you will select while moving them.

You can also get the same result by the following steps:

  1. select lines by Shift + Up/Down
  2. split selection into lines (of selections): Cmd + Shift + L
import sublime, sublime_plugin

class SelectToEndoflineCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        caretPos = self.view.sel()[0].begin()
        self.view.sel().add(sublime.Region(caretPos, self.view.line(caretPos).end()))

class SelectToBegoflineCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        caretPos = self.view.sel()[0].begin()
        self.view.sel().add(sublime.Region(caretPos, self.view.line(caretPos).begin()))

robertcollier4's answer solved the question for me. For some reason the super+shift+right default OSX keybinding is overwritten in Sublime Text 3, and there is no way to properly unbind it in the user-key-bindings.

To add robert's code as a plugin go to Tools > New Plugin, paste the code, save it and add a reference to it in your keymapping:

[
    { "keys": ["super+shift+right"], "command": "SelectToEndoflineCommand" }
]

The only change I made to it was to change

caretPos = self.view.sel()[0].begin()

to

caretPos = self.view.sel()[0].end()

for the EOL function, otherwise it won't work correctly for multi-line selections.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top