在 macOS 终端中打开 Sublime Text

567

当我在终端中使用.subl命令时,会返回-bash: .subl: command not found

有人知道如何在macOS的命令行中打开Sublime Text 3吗?


4
你对此有什么进展?我也在使用 ST3 的时候遇到了 subl 的问题。我已经在 /usr/local/bin/subl 创建了符号链接,它指向 /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl。我甚至在我的 ~/.bash_profile 中添加了 export PATH=/usr/local/bin:$PATHexport EDITOR="subl -w",但它仍然无法正常工作,并且我收到相同的错误提示。 - rs77
我遇到了一个奇怪的问题,必须打开subl文件夹才能执行命令。以下是执行的命令:Angelfirenze$ /Applications/Sublime\ Text\ 3.app/Contents/SharedSupport/bin/subl ; exit; logout Saving session... ...copying shared history... ...saving history...truncating history files... ...completed. [Process completed] Sublime Text 3最终在新会话中打开。我已经安装了Homebrew并按照说明进行了操作。 - Angelfirenze
7
如果您想从命令行打开文件file.txt,可以使用命令open -a "Sublime Text" file.txt更适合。这将使用Sublime Text打开指定的文本文件,而不需要手动打开软件后再打开文件。 - mareoraft
命令不是.subl,而是subl - the Tin Man
修改了.bash_profile文件后,请确保关闭终端并重新打开。这是唯一真正帮助我的方法。我想确保没有人会被卡在这个明显但非常重要的步骤上^^ - SHANNAX
33个回答

0

对于Sublime 4+,使用Bash更加简单:

echo 'export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"' >> ~/.bash_profile

0

默认路径中创建文件对我没有发挥作用,因为Menu.sublime-menu文件已经覆盖了几乎所有其他菜单选项,只留下了自定义的一个

对我有效的是在路径~/Library/Application Support/Sublime Text 3/Packages/User/Main.sublime-menu中创建以下文件(请注意目录User而不是Default):

[
    {
        "caption": "File",
        "mnemonic": "F",
        "id": "file",
        "children":
        [
            {
                "caption": "Open Recent More",
                "children":
                [
                    { "command": "open_recent_file", "args": {"index": 1 } },
                    { "command": "open_recent_file", "args": {"index": 2 } },
                    { "command": "open_recent_file", "args": {"index": 3 } },
                    { "command": "open_recent_file", "args": {"index": 4 } },
                    { "command": "open_recent_file", "args": {"index": 5 } },
                    { "command": "open_recent_file", "args": {"index": 6 } },
                    { "command": "open_recent_file", "args": {"index": 7 } },
                    { "command": "open_recent_file", "args": {"index": 8 } },
                    { "command": "open_recent_file", "args": {"index": 9 } },
                    { "command": "open_recent_file", "args": {"index": 10 } },
                    { "command": "open_recent_file", "args": {"index": 11 } },
                    { "command": "open_recent_file", "args": {"index": 12 } },
                    { "command": "open_recent_file", "args": {"index": 13 } },
                    { "command": "open_recent_file", "args": {"index": 14 } },
                    { "command": "open_recent_file", "args": {"index": 15 } },
                    { "command": "open_recent_file", "args": {"index": 16 } },
                    { "command": "open_recent_file", "args": {"index": 17 } },
                    { "command": "open_recent_file", "args": {"index": 18 } },
                    { "command": "open_recent_file", "args": {"index": 19 } },
                    { "command": "open_recent_file", "args": {"index": 20 } },
                    { "command": "open_recent_file", "args": {"index": 21 } },
                    { "command": "open_recent_file", "args": {"index": 22 } },
                    { "command": "open_recent_file", "args": {"index": 23 } },
                    { "command": "open_recent_file", "args": {"index": 24 } },
                    { "command": "open_recent_file", "args": {"index": 25 } },
                    { "command": "open_recent_file", "args": {"index": 26 } },
                    { "command": "open_recent_file", "args": {"index": 27 } },
                    { "command": "open_recent_file", "args": {"index": 28 } },
                    { "command": "open_recent_file", "args": {"index": 29 } },
                    { "command": "open_recent_file", "args": {"index": 30 } },
                    { "command": "open_recent_file", "args": {"index": 31 } },
                    { "command": "open_recent_file", "args": {"index": 32 } },
                    { "command": "open_recent_file", "args": {"index": 33 } },
                    { "command": "open_recent_file", "args": {"index": 34 } },
                    { "command": "open_recent_file", "args": {"index": 35 } },
                    { "command": "open_recent_file", "args": {"index": 36 } },
                    { "command": "open_recent_file", "args": {"index": 37 } },
                    { "command": "open_recent_file", "args": {"index": 38 } },
                    { "command": "open_recent_file", "args": {"index": 39 } },
                    { "command": "open_recent_file", "args": {"index": 40 } },
                    { "command": "open_recent_file", "args": {"index": 41 } },
                    { "command": "open_recent_file", "args": {"index": 42 } },
                    { "command": "open_recent_file", "args": {"index": 43 } },
                    { "command": "open_recent_file", "args": {"index": 44 } },
                    { "command": "open_recent_file", "args": {"index": 45 } },
                    { "command": "open_recent_file", "args": {"index": 46 } },
                    { "command": "open_recent_file", "args": {"index": 47 } },
                    { "command": "open_recent_file", "args": {"index": 48 } },
                    { "command": "open_recent_file", "args": {"index": 49 } },
                    { "command": "open_recent_file", "args": {"index": 50 } }
                ]
            }
        ]
    }
]

结果:

(为了安全起见,需要对图像的某些部分进行模糊处理)

open-recent-more.png


-1

我用的是Mac,这个方法对我有效:

open /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接