I want to use Sublime Text 2 for editing Git commit messages. Right now I have the following in my bash rc file:

export EDITOR="sublime -nw"

This works well if Sublime is already running. But if it's not, Sublime starts up with 2 windows rather than 1: one for my Git commit message, and one with the project I was working on most recently. And before Git stops waiting for me to finish editing, I have to close both of those windows.

Is there a better way to set EDITOR which works around this problem?


After posting this question on StackOverflow about a year ago (and being told the question belonged on Superuser), I have come up with a setup which works really well:

  • ~/.bin/start_sublime:

    # this script ensures that Sublime Text is running
    if [ ! "$(pidof sublime_text)" ] ; then
      # start up an instance of Sublime
      "/home/alex/Downloads/programs/Sublime Text 2/sublime_text" &
      sleep 1 # avoid race condition
  • ~/.bin/sub_new_block

This opens a new window, and waits for you to close that window only, not any other Sublime window which you may have had open. This makes it work just right for editing patches or commit messages in git, etc:

   "/home/alex/Downloads/programs/Sublime Text 2/sublime_text" -nw $FILE
  • ~/.bin/sub_existing_noblock:

This uses an existing window if there is one, and the shell does not wait for you to close the window:

    "/home/alex/Downloads/programs/Sublime Text 2/sublime_text" $FILE &
  • ~/.bin/sub_new_noblock:

This always opens a new window, and again the shell does not wait for you to close the window:

    "/home/alex/Downloads/programs/Sublime Text 2/sublime_text" -n $FILE &

For general editing, sub_new_noblock seems to be the most useful variant, so I alias it as sub. For git, I use the following config: git config --global core.editor sub_new_block. For other programs which launch an editor, I configure them to use whichever script is most appropriate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.