在我使用.subl
返回-bash: .subl: command not found
任何人都知道如何从macOS命令行打开Sublime Text 3?
答案 0 :(得分:587)
我终于在我的OSX盒子上工作了。我使用这些步骤来实现它:
从ST安装中测试subl
:
首先,导航到您希望ST打开的终端中的小文件夹,然后输入以下命令:
/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl .
注意:您可能需要将上述命令中的Sublime\ Text.app
替换为Sublime\ Text\ 3.app
或Sublime\ Text\ 2.app
,具体取决于应用程序在{{1}中的存储位置}} 目录。上面命令末尾的Applications
打开您所在的当前工作目录(再次确保您所在的目录中只包含几个文件!)。
如果您没有让Sublime Text打开您当前的工作目录,那么下一组步骤将无效。如果没有任何反应或者您从终端收到错误,那将是因为它无法找到Sublime Text应用程序。这意味着你必须检查你输入的内容(拼写等)或者没有安装Sublime Text!
检查“.bash_profile”:
现在是时候在.
文件夹中创建符号链接,但在此之前,让我们使用PATH
检查您的个人资料文件。以下这些行与nano ~/.bash_profile
在Sublime Text的命令行上工作有关:
subl
第一行设置您希望终端在您的计算机上查找二进制文件的位置,我将在export PATH=/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$PATH
export EDITOR='subl -w'
目录中存储我的符号链接 - 我想您可以将它存储在任何位置通知终端在哪里寻找二进制文件。
第二行是OPTIONAL,只是将Sublime Text设置为默认编辑器。已添加标记/usr/local/bin
,您可以转到Sublime Text文档找到有关标记的更多信息:ST3 subl或ST2 subl
如果您在关闭文件后对该文件进行了任何编辑,则需要运行以下命令:
-w
编译新应用的编辑。如果您在获取文件后发现任何错误,请在转到最后一步之前将其修复。
创建指向Sublime Text的符号链接:
现在,在您选择的路径中(我使用source ~/.bash_profile
),您现在输入以下命令:
/usr/local/bin
ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
与您输入并验证为在上面的步骤1中工作的位置完全相同。 /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl
是您希望符号链接所在的位置 - 需要是上述步骤2中/usr/local/bin/subl
个位置之一。
现在,当您导航到要在Sublime Text中打开的文件夹或文件时,现在只需输入PATH
,然后输入文件名或subl
即可打开当前工作目录。< / p>
希望这有帮助!
答案 1 :(得分:256)
对于MAC 10.8 +
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
工作!
答案 2 :(得分:126)
假设:
1.您已经安装了Homebrew。
2. / usr / local / bin是你的$ PATH。
你在优胜美地或El Capitain。
已编辑 2017年8月4日:MacOS Sierra 10.12.5的工作得到了David Rawson的证实,MacOS Sierra 10.12.6得到了Alexander K的确认。
解决方案:首先,在终端应用上运行以下脚本以创建特定的 符号链接。
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
然后,
subl .
点击返回,它应该立即弹出Sublime app。
答案 3 :(得分:64)
这对我有用(我正在使用OS X Mavericks)
首先,创建一个符号链接:
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/bin/subl
现在您可以使用
打开sublimesubl "/a/path/to/the/directory/you/want/to/open"
答案 4 :(得分:59)
我在Mac OSX Mavericks上使用oh-my-zsh并且符号链接对我不起作用,所以我在.zshrc文件中添加了别名:
alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"
打开一个新终端,你应该好好去,然后输入subl
。
答案 5 :(得分:36)
我将使用的那个非常简单。
open -a "sublime text" [file]
这会立即打开崇高文本。您可以指定要作为可选参数打开的文件,例如在当前目录中打开“myfile.txt”。
答案 6 :(得分:27)
有一种简单的方法可以做到这一点。它只需要几个步骤,您不需要太多使用命令行。如果您是命令行的新用户,则可以使用此方法。
第1步:查找bin文件以将subl可执行文件放入
cd ..
---------------------这应该返回目录ls
------------------------以查看目录中的文件列表cd ..
---------------------直到您获得包含 usr 的文件夹open usr
---------------这应该打开查找器,你应该看到一些文件夹第2步:查找可执行文件
subl
--------------中的终端类型中,这应该打开Sublime Text 确保它被复制并且它不是快捷方式。如果确实有问题,请将usr / bin文件夹视为图标,然后将 subl 粘贴到文件夹中的空白区域。它不应该在图标图像中有一个快捷箭头。
答案 7 :(得分:16)
试试这个。
ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
答案 8 :(得分:16)
Sublime Text 3文档中的符号链接命令无法正常工作,因为Mac OS X El Capitan或更高版本的Home位置中没有~/bin/
目录。
因此,我们需要将符号链接放在/usr/local/bin
上,因为此路径在大多数情况下都位于$PATH
变量中。
因此,以下命令应该可以解决问题:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
正确创建符号链接后,您就可以像这样运行Sublime Text 3:subl .
(。表示当前目录)
答案 9 :(得分:11)
请注意,不要写入/usr/bin
,而应写入/usr/local/bin
。
第一个用于将二进制文件写入系统的应用程序,最新版本用于制作我们自己的系统范围二进制文件的特定用法(这是我们在符号链接时的情况)。
同样/usr/local/bin
在/usr/bin
之后读取,因此也是覆盖任何默认应用的好地方。
考虑到这一点,正确的符号链接将是:
ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
答案 10 :(得分:10)
在运行Sublime Text 2的OS X Mavericks中,以下内容对我有用。
sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/bin/subl
将文件放在查找器中并将其拖放到终端窗口中,这样可以确保路径是正确的,我不是一个庞大的终端用户,所以这对我来说更舒服。然后你可以转到路径的开头并开始添加其他部分,如速记UNIX命令。希望这有帮助
答案 11 :(得分:9)
您可以在终端中创建新别名:
nano ~/.bash_profile
复制此行并将其粘贴到编辑器中:
alias subl='open -a "Sublime Text"'
按 control + x ,然后 y ,然后输入以保存并关闭它。
关闭所有终端窗口并再次打开它。
就是这样,您现在可以使用subl filename
或subl .
答案 12 :(得分:9)
它有效!!!!对我来说,MacOS Sierra 10.12.2
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
并在终端subl
答案 13 :(得分:8)
关闭Sublime。运行此命令。它会卸载它。你不会丢失你的prefs。然后再次运行它。它会自动绑定subl
。
brew install Caskroom/cask/sublime-text
答案 14 :(得分:6)
除非你真的需要,否则你不应该污染/ usr / bin目录。 我总是使用/ usr / local / bin来处理那些不受分发包管理器管理的二进制文件。为什么?因为如果包管理器得到更新,它将始终替换/ usr / bin中的文件。
所以我要做的是
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
答案 15 :(得分:5)
将此添加到.bashrc或.zshrc是一个简单的解决方案。
alias sublime="open -a /Applications/Sublime\ Text.app"
答案 16 :(得分:4)
答案 17 :(得分:4)
您只需添加别名
即可alias subl='/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'
然后你应该能够用
打开一个文件夹或其他东西subl <path>
答案 18 :(得分:3)
对于那些希望在终端
上使用Sublime打开文件的人open 'path/file.txt' -a '/Applications/Sublime Text.app'
答案 19 :(得分:3)
这是为了让它作为ALIAS工作,而不是符号链接!
这将允许您在终端中运行其他命令而不会中断subl会话。使用此处的许多符号链接答案(ln -s
)会导致终端进程在使用Sublime文本时忍受。如果您想要分离,请在Bash配置文件中创建一个别名,如下所示:
从ST安装中测试subl
:
首先,导航到您希望ST打开的终端中的文件夹,然后输入以下命令:
/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl .
注意:您可能需要将上述命令中的Sublime\ Text.app
替换为Sublime\ Text\ 3.app
或Sublime\ Text\ 2.app
,具体取决于应用程序在{{1}中的存储位置}} 目录。上面命令末尾的Applications
打开您所在的当前工作目录(再次确保您位于仅包含少量文件的目录中。)。
如果您没有让Sublime Text打开您当前的工作目录,那么下一组步骤将无效。如果没有任何反应或者您从终端收到错误,那将是因为它无法找到Sublime Text应用程序。这意味着你必须检查你输入的内容(拼写等)或者没有安装Sublime Text!
检查并更新&#34; .bash_profile&#34;:
现在在Bash配置文件中添加别名。通过.
打开它。以下这些行与vim ~/.bash_profile
在Sublime Text的命令行上工作有关:
subl
我建议您始终使用## For Sublime Text 3 alias
alias subl='/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'
## For Sublime Text global editor preference **Optional
export EDITOR='subl -w'
在此处评论您的代码。第二行是OPTIONAL,只是将Sublime Text设置为默认编辑器。已添加标记##
,您可以转到Sublime Text文档找到有关标记的更多信息:ST3 subl或ST2 subl
如果您在关闭此文件后对该文件进行了任何编辑,则需要在当前会话中-w
此文件或关闭终端(选项卡)并打开一个新文件。您可以通过运行命令source
来source
此文件。在转到最后一步之前解决所有错误。
答案 20 :(得分:2)
我想补充一点,如果您要从Sublime Text 2升级,请先进入/ usr / bin并先删除旧的subl,然后再按照上述说明操作。值得升级。
答案 21 :(得分:2)
以下内容对我有用
open -a Sublime\ Text file_name.txt
open -a Sublime\ Text Folder_Path
您可以使用别名使事件变得简单
在您的
中添加以下行〜/ .bash_profile
alias sublime="open -a Sublime\ Text $@"
然后下次您可以使用以下命令打开文件/文件夹
sublime file_name.txt
sublime Folder_Path
答案 22 :(得分:1)
我正在使用mac airbook打开你的终端并输入
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/bin/subl
然后输入简单的子标题和文件名
subl index.py
答案 23 :(得分:0)
我使用的是Oh-My-Zshell,前面提到的别名对我不起作用,因此我编写了一个简单的bash函数,该函数允许您使用sublime
从命令行打开Sublime。编辑器中的当前文件夹。具有附加功能,可指定从中打开编辑器的文件。
# Open Sublime from current folder or specified folder
sublime(){
/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl ./$1
}
用于在终端中打开当前文件夹:
$ sublime
用于打开特定文件夹:
$ sublime path/to/the/file/to/open
答案 24 :(得分:0)
总结了完成它的不同方法:
open /Applications/Sublime\ Text.app/
open -a /Applications/Sublime\ Text.app/ myFileToOpen.txt
通过引入一个名为'sublime'的新别名并使用它来使您的命令简短
a。打开bash_profile:
nano ~/.bash_profile
b。复制此行以创建别名,然后保存并重新启动终端
alias sublime="open -a /Applications/Sublime\ Text.app"
c。用法:apple.txt将以崇高的文本打开(如有必要,提供文件路径)
sublime apple.txt
答案 25 :(得分:0)
在 Default 路径中创建文件对我来说不起作用,因为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 } }
]
}
]
}
]
(出于安全原因,需要模糊图像的某些部分)
答案 26 :(得分:0)
echo 'export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"' >> ~/.zprofile
工作正常。
答案 27 :(得分:-1)
我在Mac上,这对我有用:
open /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl