简体   繁体   English

Sublime Text / subl:从命令行在特定组中打开文件

[英]Sublime Text / subl: Open file in specific group from command line

I want to open a file from command-line (using subl or other means) in Sublime Text, but it always opens in currently active group. 我想通过Sublime Text中的命令行(使用subl或其他方式)打开文件,但是它总是在当前活动组中打开。

How do I open it in specific group? 如何在特定组中打开它?

I see no option in subl for it and running command like focusGroup 0 but that too doesn't work. 我在subl中看不到任何选项,也无法运行诸如focusGroup 0类的命令,但这也行不通。

Use case: I use ST with TerminalView plugin, so first group has all files to edit and second group has bash terminal open. 用例:我将ST与TerminalView插件一起使用,因此第一组可以编辑所有文件,第二组可以打开bash终端。 Idea is to open a file in first group through command line in terminal (second group). 想法是通过终端(第二组)中的命令行在第一组中打开文件。 As of now the file opens in second group. 截至目前,该文件在第二组中打开。

To achieve this, we need to find what the correct command is to focus the first group. 为了实现这一目标,我们需要找到正确的命令来聚焦第一组。 In ST, from the View menu, select Show Console, and then enter sublime.log_commands(True) Enter , followed by focusing group 1 from the menu: View -> Focus Group -> Group 1. We will see the following in the console: 在ST中,从“视图”菜单中选择“显示控制台”,然后输入sublime.log_commands(True) Enter ,然后从菜单中选择焦点组1:“视图”->“焦点组”->“组1”。我们将在控制台中看到以下内容:

command: focus_group { "group": 0 } 命令:focus_group {“ group”:0}

Now, to run this command from the command line: 现在,要从命令行运行此命令:

subl --command "focus_group { \"group\": 0 }"

Then, to open the file: 然后,打开文件:

subl /path/to/file

This can be shortened to: 可以简化为:

subl --command "focus_group { \"group\": 0 }" && subl /path/to/file

But trying to shorten it to one subl invocation will open the file before running the command, meaning it will open in group 2, then switch focus to group 1. 但是尝试将其缩短为一个subl调用将在运行命令之前打开文件,这意味着它将在组2中打开,然后将焦点切换到组1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM