1.1.10 命令行
优质
小牛编辑
131浏览
2023-12-01
概述
Sublime Text 包含了一个命令行工具,subl,以在命令行操作文件。在 Sublime Text 中这可以被用来打开文件或项目,也可以像 unix 工具一样作为一个EDITOR使用,如作为git和subversion。
起步
第一步是给subl添加一个链接。假设你已经把 Sublime Text 放到了Applications
文件夹下,并且你的路径下有~/bin
目录,你可以运行:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
使用
执行subl —help
,
Usage: subl [arguments] [files] edit the given files
or: subl [arguments] [directories] open the given directories
or: subl [arguments] - edit stdin
Arguments:
--project <project>: Load the given project
--command <command>: Run the given command
-n or --new-window: Open a new window
-a or --add: Add folders to the current window
-w or --wait: Wait for the files to be closed before returning
-b or --background: Don't activate the application
-s or --stay: Keep the application activated after closing the file
-h or --help: Show help (this message) and exit
-v or --version: Show version and exit
--wait is implied if reading from stdin. Use --stay to not switch back
to the terminal when a file is closed (only relevant if waiting for a file).
Filenames may be given a :line or :line:column suffix to open at a specific
location.
EDITOR
要把 Sublime Text 作为许多命令的 editor 来给输入增加提示,设置 EDITOR 的环境变量:
export EDITOR='subl -w'
指定-w
表示只有文件关闭时subl
命令才会退出。