在终端中使用。subl
它返回-bash: .subl:命令未找到
有人知道如何在macOS的命令行打开Sublime Text 3吗?
在终端中使用。subl
它返回-bash: .subl:命令未找到
有人知道如何在macOS的命令行打开Sublime Text 3吗?
当前回答
你可以在Terminal中创建一个新的别名:
nano ~/.bash_profile
复制这一行并粘贴到编辑器中:
alias subl='open -a "Sublime Text"'
点击control + x,然后y,然后回车保存并关闭它。
关闭所有终端窗口并重新打开。
就是这样,你现在可以使用subl filename或subl。
更新zsh:
自macOS 10.15 Catalina开始,默认shell更改为zsh。
nano ~/.zshrc
其余步骤保持不变。
其他回答
我正在使用mac airbook打开你的终端并键入
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/bin/subl
然后键入简单的subl和文件名
subl index.py
我终于让这个在我的OSX盒子上工作了。我使用以下步骤让它工作:
Test subl from your ST installation: First, navigate to a small folder in Terminal that you want ST to open and enter the following command: /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl . NOTE: You may need to replace Sublime\ Text.app in the command above to Sublime\ Text\ 3.app or Sublime\ Text\ 2.app depending upon where the application is stored in your Applications directory. The . at the end of the above command opens the current working directory you are located in (again make sure you're in a directory that only contains a few files!). If you DO NOT get Sublime Text opening your current working directory then the next set of steps will NOT work. If nothing happens or you get an error from Terminal it will be because it couldn't find the Sublime Text application. This would mean that you would have to check what you've typed (spelling, etc.) OR that Sublime Text isn't installed! Check ".bash_profile": Now it's time to create your symbolic link in your PATH folder, BUT, before we do, let's check your profile file by using nano ~/.bash_profile. These are the following lines that pertain to having subl work on the command line for Sublime Text: export PATH=/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$PATH export EDITOR='subl -w' The first line sets the location where you want Terminal to look for binaries on your machine, I'm going to store my symbolic link in the /usr/local/bin directory - I guess you could store it anywhere provided you've notified Terminal where to look for binaries. The second line is OPTIONAL and just sets Sublime Text as the default editor. The flag -w has been added and you can find out more about flags by going to the Sublime Text docs: ST4 subl, ST3 subl or ST2 subl If you do make any edits to this file once you have closed it, you need to run the command: source ~/.bash_profile to compile your newly applied edits. If you see any errors after sourcing your file get them fixed before moving to the final step. Create a symbolic link to Sublime Text: Now in your chosen path (I used /usr/local/bin) you now enter the following command: ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl The /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl being EXACTLY the same location as what you entered and verified as working in STEP 1 above. The /usr/local/bin/subl being the location of where you want the symbolic link to be located - needs to be one of your PATH locations from STEP 2 above. Now when you navigate to a folder or file that you want to open in Sublime Text you now just enter subl followed by the name of the file or . to open the current working directory.
遵循Sublime文档即可
Bash
echo 'export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"' >> ~/.bash_profile
ZSH
echo 'export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"' >> ~/.zprofile
Linux
sudo ln -s /opt/sublime_text/sublime_text /usr/local/bin/subl
执行命令后,请务必关闭终端。
使用
要查看可用的标志,运行subl——help。
总结一下实现目标的不同方法:
从终端打开崇高文本
open /Applications/Sublime\ Text.app/
使用sublime text打开当前路径下的特定文件(或提供需要打开的文件的路径)
open -a /Applications/Sublime\ Text.app/ myFileToOpen.txt
通过引入一个名为“sublime”的新别名并使用它,使您的命令变得简短 A. open bash_profile: 纳米~ / . bash_profile B.复制这一行以创建别名并保存并重启终端 alias sublime="open -a /Applications/ sublime \ Text.app" apple.txt将以sublime文本打开(必要时提供文件路径) 崇高apple.txt
这是为了让它作为一个别名工作,而不是一个符号链接!
这将允许您在终端中运行额外的命令,而不会中断子会话。使用这里的许多符号链接答案(ln -s),导致终端进程在使用Sublime文本时持续。如果你想要分离,在Bash配置文件中创建一个别名,如下所示:
Test subl from your ST installation: First, navigate to a folder in Terminal that you want ST to open and enter the following command: /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl . NOTE: You may need to replace Sublime\ Text.app in the command above to Sublime\ Text\ 3.app or Sublime\ Text\ 2.app depending upon where the application is stored in your Applications directory. The . at the end of the above command opens the current working directory you are located in (again make sure you're in a directory that only contains a few files!). If you DO NOT get Sublime Text opening your current working directory then the next set of steps will NOT work. If nothing happens or you get an error from Terminal it will be because it couldn't find the Sublime Text application. This would mean that you would have to check what you've typed (spelling, etc.) OR that Sublime Text isn't installed! Check and update ".bash_profile": Now add the alias in your Bash Profile. Open it via vim ~/.bash_profile. These are the following lines that pertain to having subl work on the command line for Sublime Text: ## 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' I suggest always commenting your code in here with ##. The second line is OPTIONAL and just sets Sublime Text as the default editor. The flag -w has been added and you can find out more about flags by going to the Sublime Text docs: ST3 subl or ST2 subl If you do make any edits to this file once you have closed it, you need to source this file in your current session or close the terminal (tab) and open a new one. You can source this file by running the command source ~/.bash_profile Resolve any errors before moving to the final step.