I installed Sublime Text and wanted to know how to open rb
files in it from the terminal. I saw What is the command to make Sublime Text my core editor? and I s
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).
create in registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\sublime.exe
update value of default parameter (REG_SZ) to:
C:\Program Files\Sublime Text 2\sublime_text.exe
If you don't want to change your path you can associate files with sublime. So right click on the file, click properties, then click opens with sublime text.
From the command line:
myFile.py
Will open the file in sublime. I suppose this saves you about five keystrokes.
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" $*
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
add Sublime's installation folder to your path.
@set PATH=C:\Program Files\Sublime Text 3;%PATH%
or
To set an environment variable permanently in Windows (so that it is available to all the Windows' processes),
start the "Control Panel" ⇒ "System" ⇒ (Vista/7/8) "Advanced system settings" ⇒ Switch to "Advanced" tab ⇒ "Environment variables" ⇒ Choose "System Variables" (for all users) or "User Variables" (for this login user only) ⇒ Choose "Edit" (for modifying an existing variable) or "New" (to create a new variable) ⇒ Enter the variable "Name" and "Value".
in that case prepend C:\Program Files\Sublime Text 3 to the path.
Now, can make a copy of 'sublime_text.exe' as 'sublime.exe'
Then in any command prompt you may be able to run a file.txt file by
C:\Users\MyUsername>sublime filename.txt
This powershell allows me to pipe to the edit function (or to use it in the normal way)
function edit
{
param( [Parameter(ValueFromPipeline=$true,Position=0)] $file )
begin { set-alias EDITOR 'W:\tools\sublime_text.bat' }
process { EDITOR $file }
}
here is the sublime_text.bat
which for some reason seems necessary (anyone know why?)
START "Sublime Text 2" "C:\Program Files\Sublime Text 2\sublime_text.exe" %*