Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text from Command Line

People also ask

How do I get Sublime Text from command prompt?

Open any program file in the sublime editor and Right-click (context menu). You can see the Cmd menu in the Context menu options. Click on it. The command prompt will be opened through which you can compile and run your program.

Does Sublime Text have command line?

Sublime Text includes a command line tool, subl , to work with files on the command line. This can be used to open files and projects in Sublime Text, as well working as an EDITOR for unix tools, such as git and subversion.

How do I open a Sublime Text file in Terminal?

Just Use the command subl to open sublime text from terminal. if you want to open a specific file use subl path/to/the/file .


Windows Command Prompt

For Windows cmd.exe you could just add the sublime text installation directory to your PATH environment variable, this would allow you to type:

sublime_text file.rb

Personally, I add a doskey (in a .bat file set to autorun with cmd) so I can type subl file.rb:

> doskey subl="C:\Program Files\Sublime Text 2\sublime_text.exe" $*

Cygwin

For the default bash shell add an alias to your ~/.bashrc file, e.g:

$ echo 'alias subl="/cygdrive/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe"' >> ~/.bashrc

From build 3065 (Release Date: 29 August 2014) onwards Sublime text includes a command line helper, nameley subl.exe. It is at sublime's installation folder: copy it in to a folder included in the system path. For example, in my case I copied it

from C:\Program Files\Sublime Text 3

to C:\Windows\System32

You may then use in your terminal/console subl as a command to open whatever file, such as in your example:

subl file.rb

Or you may as well modify your system PATH variable to include sublime's instalation folder, but I believe that is much more involved.


I added this to my PowerShell profile:

Set-Alias subl 'C:\Program Files\Sublime Text 2\sublime_text.exe'

Modify this as needed for Sublime Text 3 (or any future versions).


Another idea would be to include C:\Program Files\Sublime Text 2\ in your PATH, and then run an administrator command prompt:

cd "C:\Program Files\Sublime Text 2\"
mklink sublime.exe sublime_text.exe

That will make a symbolic link with the new name. And now you can use it freely:

sublime hello.txt

Update: After having a chance to use this trick and update Sublime Text 2, I'm happy to say that updating to a new build doesn't affect the symbolic link.