Reputation: 560
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?
Upvotes: 21
Views: 37090
Reputation: 89
You can achieve it by removing the spaces at the end of each line. Workflow in Sublime is:
option+command+F
which is find and replaceoption+command+R
Decide how many spaces from the end need to be deleted. Let's say at least 4 spaces,
*
and replace it nothing.Upvotes: 0
Reputation: 1313
For sublime text 2 - consider the answers above such as Bart & Robert's solution
For sublime text 4 (and likely 3) - you can create custom keybindings that differentiate between moving and selecting without any extra functions. You just need to set the extends
option appropriately. For example, here's my Default (linux).sublime-keymap
file:
[
{"keys": ["super+left"], "command": "move_to", "args": {"to": "bol", "extend": false}},
{"keys": ["super+right"], "command": "move_to", "args": {"to": "eol", "extend": false}},
{"keys": ["super+shift+left"], "command": "move_to", "args": {"to": "bol", "extend": true}},
{"keys": ["super+shift+right"], "command": "move_to", "args": {"to": "eol", "extend": true}}
]
Note how the only difference above is in how I set extends: false
for moving only, but for moving and selecting I set extends: true
. If you want to support both moving and selecting, from my experience so far you need to have both custom lines in there.
Upvotes: 1
Reputation: 4921
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:
Upvotes: 10
Reputation: 1008
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.
Upvotes: 2
Reputation: 752
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()))
Upvotes: 2
Reputation: 847
You can also get the same result by the following steps:
Upvotes: 3
Reputation: 1847
If I've understood your question correctly, you can do that with the following keys (example with OS X keybindings):
The related keybindings for all OS's: http://www.sublimetext.com/docs/2/column_selection.html
Upvotes: 37