Ghopper21
Ghopper21

Reputation: 10477

In Sublime Text 2, how to select beginning and end of selected block?

The old docs for Sublime Text have this tantalizing note:

Given a selected block of text, Ctrl+Shift+K will split it into two selections, one for each end.

That'd be quite handy, but it doesn't work in Sublime Text 2, at least not on my Mac. (Instead, the keystroke deletes the current line.)

I know it's easy enough to map any Sublime command to any keystroke, but I despite looking around I can't find the command for split-selected-block-into-start-and-end-selections.

So, what's the command for this? Or otherwise how can I do this?

Upvotes: 3

Views: 7416

Answers (4)

oobug
oobug

Reputation: 942

While I recognize this question is now over a year old, I think this is a highly desirable feature. I haven't created a package for this yet, but I did create a plugin that will do the trick. Create a Python file (suggested name: selections.py) in your Sublime Text 2/Packages/User directory, and copy in the following code.

import sublime, sublime_plugin

def split_selection_to_begin_end(view):
    new_sel = []
    for s in view.sel():
        if not s.empty():
            new_sel.append(sublime.Region(s.a))
            new_sel.append(sublime.Region(s.b))
        else:
            new_sel.append(s)

    view.sel().clear()
    for s in new_sel:
        view.sel().add(s)


class SplitSelectionToBeginEndCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        split_selection_to_begin_end(self.view)

I decided to set the keystroke for this to Ctrl+Shift+; since it's convenient and wasn't mapped to anything in any of the packages I have installed. Add this or something similar to your User/Default (OS).sublime-keymap file.

[
    { "keys": ["ctrl+shift+;"], "command": "split_selection_to_begin_end" }
]

Upvotes: 3

Jaime
Jaime

Reputation: 1

Don't know about a shortcut, but you can do CTRL+Left Click(mouse) at the beginning and end of a block.

Upvotes: 0

jumperchen
jumperchen

Reputation: 1473

using Ctrl+Shift+L, or Command+Shift+L on OS X, for more details refer to this - Multiple Selection with the Keyboard

Upvotes: 2

Adrien
Adrien

Reputation: 2206

It seems this have been removed in ST2. Take a look at this gist to have the list of the shortcuts of ST2 : Sublime Text 2 – Useful Shortcuts (Mac OS X)

Upvotes: 1

Related Questions