【问题标题】:Showing the same file in both columns of a Sublime Text window在 Sublime Text 窗口的两列中显示相同的文件
【发布时间】:2014-07-20 09:33:51
【问题描述】:

当我在 Sublime Text 窗口中设置了 2 列时,我可以在两列中显示同一个文件吗?

【问题讨论】:

    标签: sublimetext3 sublimetext2 sublimetext sublimetext4


    【解决方案1】:

    编辑

    随着 Sublime Text 4 的发布,现在有一个称为拆分视图的功能,您可以通过几种不同的方式访问它。通过菜单系统,您可以简单地使用File -> Split View。您也可以右键单击选项卡并从上下文菜单中选择 Split View。它会自动打开一个新窗格,其中包含当前所选文件的新视图。

    您应该知道,与下面描述的新窗格不同,新的拆分视图窗格是临时的。这意味着如果您单击另一个选项卡或打开一个新文件,拆分视图就会消失。但是,文件的新视图仍作为单独的选项卡打开,因此要重新打开窗格(或比较任何打开的文件),请在左侧选择所需的选项卡,然后 Ctrl-在要比较的其他选项卡上单击(Command ⌘-单击 macOS),每个选项卡都将显示在其自己的窗格中。

    如果想要有两个(或更多)“永久”窗格,无论您单击哪个选项卡,都将保持打开状态,只需按照以下说明操作即可。


    原答案

    (对于 Sublime Text 3)

    是的,你可以。打开文件后,点击File -> New View Into File。然后,您可以将新选项卡拖到另一个窗格并查看文件两次。

    有几种方法可以创建新窗格。如其他答案所述,在 Linux 和 Windows 上,您可以使用 AltShift2Option ⌥Command ⌘2 on OS X),对应菜单中的View → Layout → Columns: 2。如果你安装了优秀的Origami插件,你可以使用View → Origami → Pane → Create → Right,或者CtrlKCtrl Windows/Linux 上的 kbd> 和弦(在 OS X 上将 Ctrl 替换为 )。

    【讨论】:

    • Ctrl+Shift+2 分屏快捷键并拖动文件
    • 您也可以使用Windows+Ctrl+箭头键来排列窗口。
    • 下一篇文章中的 cmd 有效 - shift + Alt + 2 拆分为 2 个屏幕,而不是下面的这个。
    • @LEDFantom 当你说这个答案不起作用时,你是什么意思? OP 已经知道如何创建拆分窗口,这就是为什么我没有在回答中解释如何做到这一点。我不确定投反对票的目的是什么。
    • @GabrielStaples 感谢您的提示,我已将答案扩展为包括拆分视图。
    【解决方案2】:

    我经常在 2 个不同的位置处理同一个文件。我在 Sublime Text 3 中使用 origamichain 以及一些额外的配置解决了这个问题。

    我的工作流程是 Ctrl + k + 2 将文件视图拆分为两个(水平)窗格,下方的窗格处于活动状态。使用 Ctrl + k + o 在窗格之间切换。完成后确保下方窗格处于活动状态,然后按 Ctrl + F4 关闭复制的视图和窗格。

    在崇高的全局设置中(不是折纸设置!)添加

    "origami_auto_close_empty_panes": true,
    

    添加以下快捷方式

      { "keys": ["ctrl+k", "2"], 
        "command": "chain", 
        "args": {
          "commands": [
            ["create_pane", {"direction": "down"}],
            ["clone_file_to_pane", {"direction": "down"}],
          ],
        }
      },
    
      { "keys": ["ctrl+k", "o"], "command": "focus_neighboring_group" },
    

    【讨论】:

    • 要使chain 命令工作(见快捷方式),您还需要安装Chain of Command package
    • @wehal3001 谢谢,已更新(还更新了全局设置,粘贴了错误的设置)。
    【解决方案3】:

    有点晚了,但我尝试扩展 @Tobia's answer 以设置由命令参数驱动的布局“水平”或“垂直”,例如

    {"keys": ["f6"], "command": "split_pane", "args": {"split_type": "vertical"} } 
    

    插件代码:

    import sublime_plugin
    
    
    class SplitPaneCommand(sublime_plugin.WindowCommand):
        def run(self, split_type):
            w = self.window
            if w.num_groups() == 1:
                if (split_type == "horizontal"):
                    w.run_command('set_layout', {
                        'cols': [0.0, 1.0],
                        'rows': [0.0, 0.33, 1.0],
                        'cells': [[0, 0, 1, 1], [0, 1, 1, 2]]
                    })
                elif (split_type == "vertical"):
                    w.run_command('set_layout', {
                        "cols": [0.0, 0.46, 1.0],
                        "rows": [0.0, 1.0],
                        "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
                    })
    
                w.focus_group(0)
                w.run_command('clone_file')
                w.run_command('move_to_group', {'group': 1})
                w.focus_group(1)
            else:
                w.focus_group(1)
                w.run_command('close')
                w.run_command('set_layout', {
                    'cols': [0.0, 1.0],
                    'rows': [0.0, 1.0],
                    'cells': [[0, 0, 1, 1]]
                })
    

    【讨论】:

      【解决方案4】:

      查看 -> 布局 -> 选择一个选项或使用快捷方式

      Layout        Shortcut
      
      Single        Alt + Shift + 1
      Columns: 2    Alt + Shift + 2
      Columns: 3    Alt + Shift + 3
      Columns: 4    Alt + Shift + 4
      Rows: 2       Alt + Shift + 8
      Rows: 3       Alt + Shift + 9
      Grid: 4       Alt + Shift + 5
      

      【讨论】:

        【解决方案5】:

        这是一个简单的插件,可以“打开/关闭拆分器”到当前文件中,就像在其他编辑器中找到的那样:

        import sublime_plugin
        
        class SplitPaneCommand(sublime_plugin.WindowCommand):
            def run(self):
                w = self.window
                if w.num_groups() == 1:
                    w.run_command('set_layout', {
                        'cols': [0.0, 1.0],
                        'rows': [0.0, 0.33, 1.0],
                        'cells': [[0, 0, 1, 1], [0, 1, 1, 2]]
                    })
                    w.focus_group(0)
                    w.run_command('clone_file')
                    w.run_command('move_to_group', {'group': 1})
                    w.focus_group(1)
                else:
                    w.focus_group(1)
                    w.run_command('close')
                    w.run_command('set_layout', {
                        'cols': [0.0, 1.0],
                        'rows': [0.0, 1.0],
                        'cells': [[0, 0, 1, 1]]
                    })
        

        将其保存为Packages/User/split_pane.py 并将其绑定到某个热键:

        {"keys": ["f6"], "command": "split_pane"},
        

        如果你想改变垂直分割变化如下

                "cols": [0.0, 0.46, 1.0],
                "rows": [0.0, 1.0],
                "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
        

        【讨论】:

          【解决方案6】:

          可以在拆分模式下编辑同一个文件。 最好在以下 youtube 视频中进行解释。

          https://www.youtube.com/watch?v=q2cMEeE1aOk

          【讨论】:

            【解决方案7】:

            它的 Shift + Alt + 2 分成 2 个屏幕。更多选项可在菜单项视图 -> 布局下找到。
            屏幕分割后,您可以使用快捷方式打开文件:
            1. Ctrl + P (来自 sublime 中的现有目录)或
            2. Ctrl + O(浏览目录)

            【讨论】:

            • 要展开,CTRL + P 将允许您多次“打开”同一个文件。
            • CTRL + O 不会
            【解决方案8】:

            在sublime编辑器中,找到名为View的Tab,

            View --> Layout --> "select your need"
            

            【讨论】:

            • View --> Layout --> "select your need" 选择您的需求 = [single,columns,rows,grids]。所以这意味着当你去 Layout 时可用的选项。首先尝试,在 Sublime 2 中测试。
            • 欣赏菜单导航,而不仅仅是一个快捷方式,它恰好适用于某些用户并且没有解释正在使用的崇高功能 - 菜单明确定义。 :)
            • 这应该是唯一被接受的,这对我有用。接受的不再起作用了。可能它在当前版本中不起作用。
            【解决方案9】:

            我建议您使用Origami。它是一个很好的分屏插件。有关键盘快捷方式的更多信息,请安装它并在重新启动 Sublime 文本后打开 Preferences->Package Settings -> Origami -> Key Bindings - Default

            针对您的具体问题,我建议您查看上述文件中与克隆文件相关的快捷方式。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2014-01-28
              • 2013-12-10
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2021-10-30
              • 2014-07-25
              • 2014-11-01
              相关资源
              最近更新 更多