Sublime Text 多重光标快捷键

5

我是emacs的狂热用户,我绝对喜欢你可以在不使用鼠标的情况下完成所有操作。我认为这个功能使得emacs非常高效。

我也是Linux上Sublime Text的忠实粉丝。我喜欢通过Ctrl+left_mouse_clik启用的多光标特性。我还发现,您可以单击Shift+alt+arrow_up_or_down来创建上方或下方行的新光标。因此,我想知道是否有一种方法可以在Sublime Text中在任何位置创建多个光标而不使用鼠标。

2个回答

6
一种可能的解决方法是使用书签(如果您还没有使用)。我不知道 Linux 的按键绑定,但您可以添加书签,然后选择所有内容。要查看您平台的绑定,请转到 Goto -> Bookmarks,它们应该按命令列出。您还可以查看默认的按键绑定文件。
第二个解决方案是使用插件。我以前写过下面的代码,不能确定/如何良好地运作,因为我记不清了。我进行了快速测试并认为它可以正常工作。
import sublime
import sublime_plugin


class MultiCursorCommand(sublime_plugin.TextCommand):
    def run(self, edit, action="add"):
        self.key = "multi_cursor"
        cursors = self.view.sel()
        saved_cursors = self.view.get_regions(self.key)
        if action == "add":
            self.view.add_regions(self.key, list(cursors) + saved_cursors, "keyword", "", sublime.DRAW_EMPTY)
        elif action == "show":
            cursors.add_all(saved_cursors)
            self.view.add_regions(self.key, [])
        elif action == "show_begin":
            saved_cursors += list(cursors)
            cursors.clear()
            cursors.add_all([c.begin() for c in saved_cursors])
            self.view.add_regions(self.key, [])
        elif action == "show_end":
            saved_cursors += list(cursors)
            cursors.clear()
            cursors.add_all([c.end() for c in saved_cursors])
            self.view.add_regions(self.key, [])
        elif action == "show_visible":
            pass
        elif action == "clear":
            self.view.add_regions(self.key, [])
        elif action == "remove":
            for cursor in cursors:
                if cursor in saved_cursors:
                    saved_cursors.remove(cursor)
            self.view.add_regions(self.key, saved_cursors, "keyword", "", sublime.DRAW_EMPTY)


class RemoveCursorCommand(sublime_plugin.TextCommand):
    def is_enabled(self):
        return len(self.view.sel()) > 1

    def run(self, edit, forward=True):
        self.view.sel().subtract(self.view.sel()[0 if forward else -1])

按键绑定通常是这样的格式

{ "keys": ["alt+a"], "command": "multi_cursor", "args": {"action": "add"} },
{ "keys": ["alt+s"], "command": "multi_cursor", "args": {"action": "show"} }

可能已经有人编写了相同功能的插件,并放到了软件包控制上,只是我不知道它们。


2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接