如何在Sublime Text中选择具有多个游标的所有其他行?

时间:2013-03-24 12:42:41

标签: sublimetext2

在Sublime Text 2中,是否可以立即选择所有其他(或奇数/偶数)行并在这些行上放置多个游标?

感谢。

4 个答案:

答案 0 :(得分:343)

  1. 查找: Ctrl + F
  2. 如果尚未启用正则表达式,请启用它们: Alt + R
  3. 输入表达式.*\n.*\n
  4. 查找全部: Alt + 输入
  5. 按左箭头取消选择,只留下光标:
  6. 现在,您在每个奇数行的开头都有一个光标。如果您想要偶数行,请按下:
  7. 根据文件的不同,文件底部可能会丢失一个光标。使用鼠标(该死!)滚动到底部,按住 Ctrl ,然后单击缺少光标的位置以将其添加到其中。

答案 1 :(得分:98)

您可以轻松完成:

  • 选择所有行或整个文档 Ctrl + A
  • 添加多个选择器: Ctrl + Shift + L (以及Mac:Command + Shift + L)

编辑:

答案 2 :(得分:11)

我正在寻找一种在崇高中选择替代线的方法。

感谢Joe Daley给出了一个非常好的答案。 虽然我意识到,如果使用正则表达式,如果文件末尾没有换行符,则不会选择文件中的最后一行。

我想改善这个答案,但我现在似乎没有足够的声誉对上述答案发表评论。

您可以在打开正则表达式的情况下使用以下搜索字符串,然后按alt + enter。接着是左箭头。这会将光标分别放在备用线上(与Joe Daley解释的步骤相同)

^.*\n.*$

答案 3 :(得分:7)

您可以尝试使用插件:Tools/New Plugin...

import sublime_plugin


class ExpandSelectionToOtherLinesCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.window().run_command("expand_selection", {"to": "line"})
        start_region = self.view.sel()[0]
        self.view.window().run_command("select_all")
        self.view.sel().subtract(start_region)

将此文件保存在Packages/User

然后,添加该插件的键绑定:

{ "keys": ["super+alt+l"], "command": "expand_selection_to_other_lines" }

此命令将选择所有其他行。当您选择其他行时,可以使用Split selection into lines命令( Ctrl + Shift + L Cmd + Shift + L

如果你想在一个快捷方式中拥有everythnig,你可以像这样修改插件:

import sublime_plugin


class ExpandSelectionToOtherLinesCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.window().run_command("expand_selection", {"to": "line"})
        start_region = self.view.sel()[0]
        self.view.window().run_command("select_all")
        self.view.sel().subtract(start_region)
        self.view.window().run_command("split_selection_into_lines")
        self.view.window().run_command("move", {"by": "characters", "forward": False})

最后一行只是删除选择,在选定行的开头留下多个游标。