如何将 sublime 默认视图设置为 2 行 [英] How to set the sublime default View to 2 rows

查看:74
本文介绍了如何将 sublime 默认视图设置为 2 行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次打开 sublime 时,我都会执行以下操作:

Everytime I open sublime I do the following:

布局

然后

行数:2

我可以更改设置,以便在打开 sublime 时这是默认设置吗?

Can I change a setting so that when I open sublime this is the default?

推荐答案

我知道没有设置可以控制新创建的窗口的布局;它们始终创建为单个文件组.最好/最简单的方法可能是使用默认键绑定来设置您想要的布局,或者将其绑定到另一个更容易访问的键,而不是通过菜单.

There is no setting I'm aware of to control the layout of newly created windows; they're always created as a single file group. Probably the best/easiest thing to do would be to use the default key binding to set the layout you want, or bind it to another more easily accessible key, rather than going through the menu.

正如在对您的问题的评论中提到的(代码可能来自这个超级用户答案),可以也可以使用插件代码解决这个问题.

As has been mentioned in the comments on your question (with code possibly from this superuser answer) it is possible to scratch this particular itch using Plugin code as well.

如链接的答案和上面的评论所示,Sublime 启动时活动窗口的布局将切换为两行布局.

As presented in the linked answer and the comments above, the layout of the active window at Sublime start up will be switched into the two row layout.

这是次优的,因为它会强制改变活动窗口的布局,即使它已经包含文件(这可能不是你想要的),它只会影响活动窗口,即使有很多(可能不会)是你想要的)并且它不会影响插件加载后创建的窗口(这绝对不是你想要的).

This is sub-optimal since it will forcefully change the layout of the active window even if it already contains files (which may not be what you want), it only affects the active window even if there are many (which may not be what you want) and it doesn't affect windows created after the plugin was loaded (which is definitely not what you want).

可以解决某些限制的版本如下.但是请注意,在 MacOS 上,在某些情况下会创建插件无法检测到的新窗口,因此根据您的操作系统,这可能仍然无法满足您的要求.

A version that works around some of the limitations is below. Note however that on MacOS there are situations in which new windows are created that plugins are unable to detect, so depending on your operating system this still may not do what you want.

在下面的代码中,对 plugin_loaded 的调用会查找当前存在的所有窗口并更改其布局,但前提是它们当前使用的是单个窗格布局.

In the code below, the call to plugin_loaded finds all windows that currently exist and changes their layout, but only if they are currently using a single pane layout.

此外,这还会侦听在运行时创建新窗口的时间,并将其布局也设置为所需的默认值.

Additionally this also listens to see when a new window has been created at run time and also sets it's layout to be the desired default as well.

要使用它,请选择 Tools >开发人员从菜单中选择 New Plugin,将存根代码替换为以下内容,然后将其作为 Python 文件保存在 Sublime 将默认为(您的 User 包)的文件夹中.

To use this, select Tools > Developer > New Plugin from the menu, replace the stub code with the following, then save it as a Python file in the folder Sublime will default to (your User package).

import sublime
import sublime_plugin


def set_default_layout(window):
    """
    Change the layout of the provided window to the desired default.
    """
    window.run_command("set_layout",  {
        "cells": [[0, 0, 1, 1], [0, 1, 1, 2]],
        "cols": [0.0, 1.0],
        "rows": [0.0, 0.5, 1.0]})

    # Make sure the top group is given the focus
    window.focus_group(0)


def plugin_loaded():
    """
    Make all windows with a single file group have the default layout.
    """
    for window in sublime.windows():
        if window.num_groups() == 1:
            set_default_layout(window)


class DefaultPaneSetter(sublime_plugin.EventListener):
    """
    Change the layout of newly created windows to be the default.
    """
    def on_post_window_command(self, window, command, args):
        if command == "new_window":
            set_default_layout(sublime.active_window())

如上所述,在 MacOS 下,有些情况下会在不调用插件正在监视的 new_window 命令的情况下创建新窗口,例如当您在没有窗口的情况下启动 Sublime 时,它​​会创建一个默认情况下,或者在打开 open_files_in_new_window 的情况下将新文件拖动到 Dock 以将其打开.

As mentioned above, there are cases under MacOS where new windows are created without invoking the new_window command that the plugin is watching for, such as when you start up Sublime with no windows and it creates a default, or when you drag a new file to the dock to open it while you have open_files_in_new_window turned on.

据我所知,除了不断检查现在是否有比几秒钟前更多的窗口之外,无法检测何时发生这种情况,但这似乎相当具有侵入性并且可能会消耗性能.

As far as I'm aware there is no way to detect when that's happening short of constantly checking to see if there are more windows now than there were a few seconds ago, but that seems fairly intrusive and potentially performance draining.

另请注意,如果您正在使用以任何方式创建新窗口的任何包,此代码可能会干扰它们,因为当包不期望它时会强制默认布局到窗口上.

Note also that if you're using any packages which in any way create new windows, this code may interfere with them by forcing the default layout onto the window when the package doesn't expect it.

这篇关于如何将 sublime 默认视图设置为 2 行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆