在 Sublime Text 2 中,如何选择所选块的开头和结尾? [英] In Sublime Text 2, how to select beginning and end of selected block?

查看:134
本文介绍了在 Sublime Text 2 中,如何选择所选块的开头和结尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sublime Text 的 旧文档 有这个诱人的注释:

The old docs for Sublime Text have this tantalizing note:

给定一个选定的文本块,Ctrl+Shift+K 将把它分成两个选择,每一端一个.

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

那会很方便,但它在 Sublime Text 2 中不起作用,至少在我的 Mac 上不起作用.(相反,击键会删除当前行.)

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.)

我知道将任何 Sublime 命令映射到任何击键都很容易,但是尽管环顾四周,我还是找不到用于 split-selected-block-into-start-and-end-selections 的命令.

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?

推荐答案

虽然我意识到这个问题已经有一年多了,但我认为这是一个非常理想的功能.我还没有为此创建一个包,但我确实创建了一个插件来解决这个问题.在您的 Sublime Text 2/Packages/User 目录中创建一个 Python 文件(建议名称:selections.py),并复制以下代码.

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)

我决定将它的击键设置为 Ctrl+Shift+; 因为它很方便并且没有映射到我安装的任何软件包中的任何东西.添加这个或类似于你的用户/默认 (OS).sublime-keymap 文件.

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" }
]

这篇关于在 Sublime Text 2 中,如何选择所选块的开头和结尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆