In this article I’ll walk through creating alias in Windows command line. I will create alias named “subl” for launching Sublime Text 3 editor from command line.
For this purpose, doskey
command is particularly useful.
Sublime Text 3 is installed in default folder on my PC, so running below command will do the trick:
doskey subl="C:\Program Files\Sublime Text 3\sublime_text.exe"
Now I can type
subl
in command prompt and system starts Sublime Text 3 editor.
There is one little catch here though. Even if I type
subl C:\tmp\file.txt
Sublime always opens new blank document.
In order to be able to pass parameter into the alias, doskey command needs to be altered slightly:
doskey subl="C:\Program Files\Sublime Text 3\sublime_text.exe"
$*
Adding “$*” at the end allows the alias to accept zero, one, or more args.
I can now type
subl C:\tmp\file.txt
and Sublime happily loads correct file.
Gotcha!
While using this alias, I discovered one very annoying thing: aliases disappear when console is restarted. Doskey command needs to be called again.
There is a way to automate loading Doskey macros (loads of information on this on google), but it requires modifying Windows registry, which I did not want.
Instead I found easier solution:
I created very simple batch file called subl.bat
:
@ECHO OFF
START "" "C:\Program Files\Sublime Text 3\sublime_text.exe" %1
And moved it to location listed in system PATH
variable, i.e. %USERPROFILE%
Now calling
subl \tmp\path.txt
Launches new instance of Sublime Text even after restarting console.
Voila!