【问题标题】:sublime text multiple cursor shortcut崇高文本多光标快捷方式
【发布时间】:2014-09-13 20:29:01
【问题描述】:

我是 emacs 的忠实用户,我非常喜欢这样一个事实,即您可以在不使用鼠标的情况下做任何事情。我认为该功能使 emacs 非常高效。

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

【问题讨论】:

    标签: sublimetext3 shortcut


    【解决方案1】:

    一种可能的解决方案是使用书签(如果您还没有的话)。我不知道我脑海中的 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】:

      我认为 PowerCursors 是您正在寻找的东西

      https://packagecontrol.io/packages/PowerCursors

      【讨论】:

        猜你喜欢
        • 2013-02-14
        • 1970-01-01
        • 1970-01-01
        • 2012-08-24
        • 1970-01-01
        • 1970-01-01
        • 2021-10-14
        • 2019-06-03
        • 1970-01-01
        相关资源
        最近更新 更多