Sublime Text多光标快捷方式

2023-12-22

我是 emacs 的忠实用户,我非常喜欢这样一个事实:无需使用鼠标即可完成所有操作。我认为这个功能让 emacs 非常高效。

我也是 Linux 上的 Sublime Text 的忠实粉丝。我喜欢您启用的多光标功能Ctrl+left_mouse_clik。我还发现你可以点击Shift+alt+arrow_up_or_down这会在上面或下面的行上创建一个新的光标。所以我想知道 sublime text 是否有一种方法可以在不使用鼠标的情况下在任何地方创建多个光标。


一种可能的解决方案是使用书签(如果您尚未使用)。我根本不知道 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"} }

人们可能已经编写了一些在包控制上的插件来做同样的事情,我只是不知道它们。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Sublime Text多光标快捷方式 的相关文章

随机推荐