目录

OS X 命令行

概述

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

安装

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

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

用途

运行subl —help,ps:mac系统下原生显示的界面不做翻译了,以免引起误会

  1. Usage: subl [arguments] [files] edit the given files
  2. or: subl [arguments] [directories] open the given directories
  3. or: subl [arguments] - edit stdin
  4.  
  5. Arguments:
  6. --project <project>: Load the given project
  7. --command <command>: Run the given command
  8. -n or --new-window: Open a new window
  9. -a or --add: Add folders to the current window
  10. -w or --wait: Wait for the files to be closed before returning
  11. -b or --background: Don't activate the application
  12. -s or --stay: Keep the application activated after closing the file
  13. -h or --help: Show help (this message) and exit
  14. -v or --version: Show version and exit
  15.  
  16. --wait is implied if reading from stdin. Use --stay to not switch back
  17. to the terminal when a file is closed (only relevant if waiting for a file).
  18.  
  19. Filenames may be given a :line or :line:column suffix to open at a specific
  20. location.

编辑器

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

  1. export EDITOR='subl -w'

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

MacPorts

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