崇高文本多光标快捷方式 [英] sublime text multiple cursor shortcut
问题描述
我是 emacs 的忠实用户,我非常喜欢这样一个事实,即您无需使用鼠标即可完成任何事情.我认为该功能使 emacs 非常高效.
I'm a huge user of emacs and I absolutly love the fact that you can do EVERYTHING without using the mouse. I thing that feature make emacs really efficient.
我也是 Linux 上 Sublime Text 的忠实粉丝.我喜欢您使用 Ctrl+left_mouse_clik
启用的多光标功能.我还发现您可以单击 Shift+alt+arrow_up_or_down
这会在上一行或下一行创建一个新光标.所以我想知道在 sublime text 中是否有一种方法可以在不使用鼠标的情况下随时随地创建多个光标.
I'm also a big fan of Sublime Text on Linux. I like the multiple cursor feature that you enable with Ctrl+left_mouse_clik
. I also found that you can click Shift+alt+arrow_up_or_down
which create a new cursor on the above or below line. So I was wondering if there was a way in sublime text to create multiple cursor wherever you want without using the mouse.
推荐答案
一种可能的解决方案是使用书签(如果您还没有).我对 Linux 键绑定一无所知,但您可以添加书签,然后全选.要查看您平台的绑定,请转到 Goto ->书签
,它们应该被命令列出.您还可以查看默认的键绑定文件.
One possible solution is to use bookmarks (if you aren't already). I don't know the Linux key bindings off the top of my head, but you can add bookmarks, then select all. To view the bindings for your platform, go to Goto -> Bookmarks
, they should be listed by the command. You can also take a look at the default key binding file.
第二种解决方案是使用插件.不久前我写了以下内容.真的不能说它是否/如何工作,因为我不记得了.对它进行快速测试使我相信它可以正常工作.
A second solution is to use a plugin. I wrote the following a while ago. Can't really say if/how well it works, as I can't remember. A quick test with it leads me to believe it works okay.
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"} }
可能有一些人编写的插件在包控制上做同样的事情,我只是不知道它们.
There are probably plugins that people have written that are on package control that do the same thing, I'm just not aware of them.
这篇关于崇高文本多光标快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!