目录

OS X 命令行

概述

Sublime Text 2有着一个命令行工具,subl,来在命令行下处理文件。它可以用来打开Sublime Text 2中的文件和项目,也可以作为unix工具的编辑器比如git和subversion。

安装

首要任务是建立一个symlink指向subl。假设你已经把Sublime Text 2放入Applications目录,并且你的path环境变量里有一个~/bin目录,你可以运行:

ln -s "/Applications/Sublime Text 2.app/contents/SharedSupport/bin/subl" ~/bin/subl
		

用途

运行subl --help,ps:mac系统下原生显示的界面不做翻译了,以免引起误会
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.
	

编辑器

要使用Sublime Text 2作为许多命令的输入提交编辑器,设置你的EDITOR环境变量:

export EDITOR='subl -w'
	

指定 -w 将会使subl命令不会退出直到文件被关闭。

MacPorts

如果你安装了MacPorts版本的Python,那么通过subl启动Sublime Text 2将不会正常工作。变通的办法,先从Finder中启动Sublime Text 2,然后通过它使用subl来交互。