Serj L aka Loremaster

Blog of Rails developer.

I always love to hear from you: hello@bloginius.com

How Set Up Sublime Text 2 as Your Default Git Editor

| Comments

If you love Sublime Text 2 as I do then you probably would like to change default git editor (which is Vim nowadays). I suppose that you have installed Sublime text.

First of all, you should install subl shortcut. To do that open your shell and print (if you already have ~/bin directory, then just use the last line of my code):

Terminal
1
2
3
$ cd ~
$ mkdir bin
$ ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl

Now restart your shell and try that:

Terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$ subl -h
Sublime Text 2 Build 2221

Usage: subl [arguments] [files]         edit the given files
   or: subl [arguments] [directories]   open the given directories
   or: subl [arguments] -               edit stdin

Arguments:
  --project <project>: Load the given project
  --command <command>: Run the given command
  -n or --new-window:  Open a new window
  -a or --add:         Add folders to the current window
  -w or --wait:        Wait for the files to be closed before returning
  -b or --background:  Don't activate the application
  -s or --stay:        Keep the application activated after closing the file
  -h or --help:        Show help (this message) and exit
  -v or --version:     Show version and exit

--wait is implied if reading from stdin. Use --stay to not switch back
to the terminal when a file is closed (only relevant if waiting for a file).

Filenames may be given a :line or :line:column suffix to open at a specific
location.

If you have the same output, then everything works great. Otherwise you should add ~/bin to your $PATH. To do that open your ~.bash_profile and append these lines to the end of the file:

.bash_profile
1
2
PATH=$PATH:~/bin
export PATH

And I think that you should restart your shell again.

Finally, to set up sublime as default editor just print in your shell that:

Terminal
1
$ git config --global core.editor "subl -n -w"

And that is all!

Comments