My all-new-favorite text editor is Sublime Text 2. This editor is blazingly fast, has a project view for simple navigation, supports syntax highlighting for allmost all formats out of the box and can be extended. I often have to work in the command line, however, I do not want to use vim. Thus, I have to start and navigate to my project in the command line as well as in my editor. Additionally, opening files in my editor instead of vim has to be done using my windows explorer.
Scripting to the rescue!
I wrote a small bash script, which can be used in cygwin/git bash environments for starting sublime:
#!/bin/sh /c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe $1 &
A few comments to this script:
- The first line indicates that this is a script which is executed using /bin/sh (the standard shell)
- The second line executes the sublime_text.exe. Note, that spaces in the folders had to be escaped using the backslash character (\).
- $1 refers to the first parameter passed to this script. This can be a file or a folder which is passed on to Sublime Text 2 which in turn automatically opens the file or in case of a folder adds it to the current project.
- The & sign at the end moves this process into the background. This allows to use the current command line further while Sublime Text 2 is running (as it is NOT running in the foreground of the command line. )
Of course, you have to chmod +x this file to make it executable and place it into a folder which is within the PATH. Perhaps renaming the script to sl would be nice in order to reduce typing.
But then, you can use the script as follows to open the current directory:
$> sublime .
Or open the test.txt file:
$> sublime test.txt
TextMate (solely available on the Mac) already has such a feature named mate.