Git: Setting Sublime Text as the Default Editor for Git (Linux Mint/Ubuntu)

Posted on September 10 2013 08:58 PM by jatten in CodeProject, Git, Linux   ||   Comments (0)

Setting up Sublime Text 2 (or the new Beta Release of version 3)  as the default editor used by Git is not overly challenging, but not necessarily obvious either. Really, we're still simply setting up the .gitconfig file with a path to sublime text. However, given that there is not, presently, a standard installation directory for Sublime Text, we first need to know where to point our .gitconfig file. Also, there are some non-obvious flags which need to be set as part of the configuration, or Sublime Text will not work properly as the Git editor.

Installing Sublime Text 2, or installing the beta release of Sublime Text 3 is not too challenging either, but again, to this point neither Linux Mint nor Ubuntu offer Sublime as part of the Synaptic Package Manager for either distro. For additional help on this, refer to my previous posts:

If you used one of the methods above, you should now have a bash script or alias named subl in your /usr/bin/ directory which allows you to refer to Sublime Text as subl from the terminal. We will point the .gitconfig file to this.

Tell Git Where Sublime Text Lives

To set the default editor in our .gitconfig file from the terminal, we can use the following command:

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

 

Notice the –n and –w flags at the end? These arguments are passed to Sublime Text, and essentially tell it to run without loading any previously open windows (the –n flag), and to wait until the user exits to pass execution back to the calling process (the –w flag, for "wait"). In this case, the calling process is Git.

Trouble Shooting

If the above doesn't work for you, then you may not have the alias or Bash script in your /usr/bin/ directory, or you may have installed Sublime Text to a different directory altogether. In this case, the command is the same, but you need to change it to include either the script name you chase, or the the full-path to Sublime Text itself:

$ git config --global code.editor "<Full Path or Script> -n -w"

 

Of course, you can always open the .gitconfig file in Sublime Text itself (or any other editor on your system), and edit the file directly, but if you are learning Linux, where's the fun in THAT? Smile

If you have other issues, feel free to mention them in the comments or email me at the address in the "Author" section of this blog.

That's it. The biggest issue most people run into with this is not knowing about the –n and –w flags, which must be included in the quotes. Without these flags, Sublime Text will open in response to a prompt from Git, but will immediately return execution to Git. Therefore, your merge edits, interactive rebase, or other such activity will fail, because Git will never see your changes.

Other Articles of Interest to Git or Linux Newcomers

 

Posted on September 10 2013 08:58 PM by jatten     

Comments (0)

Install Sublime Text 3 (beta) on Linux Mint or Ubuntu

Posted on August 25 2013 10:10 AM by jatten in Learning Linux, Linux, CodeProject   ||   Comments (1)

LKeyboard240Surprisingly, one of my more popular articles last year was a short, very basic walk-thru detailing how to install Sublime Text 2 on Ubuntu-based machines (this includes Linux Mint).

Now that beta version of Sublime Text 3 has become more and more stable, I am going to post an updated walk-thru for the new version, since the commands differ in a few places, and I have learned a few things in the intervening months (slowly – baby steps here . . .).

Image by Nick Ares / Some Rights Reserved

As noted in the previous article regarding Sublime Text 2, Sublime Text 3 is not currently part of the Synaptic Package Management system on Linux Mint (or Ubuntu). Therefore, there is no magical apt-get install command as you might use to install other software on your Linux system, so we have to do a little more work.

Installing Sublime Text on Linux Mint/Ubuntu from Tarball

You can manually download the latest build (Build 3047 as of this writing) of Sublime Text 3 for either 32 bit or 64 bit architectures from the Sublime Text 3 page, unpack, and locate in the directory of your choice. This can be done manually, or from the terminal as described below.

If you are less-than-familiar with the Bash command line, be sure to visit my previous posts. While these were originally part of a series on using Git for Windows developers, the basic Bash commands required for this install are clearly explained:

This method is described on the Sublime Text Site/Support/Linux/Installation page. Simply open a terminal in the directory you use for applications, and enter the following command (use the appropriate version fro your machine):

Note: As of this writing, Sublime Text 3 build 3059 is the most recent beta release. If the release is updated, the URL's in the links below will change, and you will need to copy the updated URL from the Sublime Text site.

Download the Linux 32-Bit Version of Sublime Text 3:
$ wget http://c758482.r82.cf2.rackcdn.com/sublime_text_3_build_3059_x32.tar.bz2

 

Download the Linux 64-Bit Version of Sublime Text 3:
wget http://c758482.r82.cf2.rackcdn.com/sublime_text_3_build_3059_x64.tar.bz2

 

Extract the "Sublime Text 2.0.1.tar.bz2" file (this will be sublime_text_3_build_3059_x64.tar.bz2 for the 64 bit version):

Extract the Sublime Text .tar file:
tar vxjf "sublime_text_3_build_3059_x32.tar.bz2"

 

It is common to locate 3rd-party applications in the /opt/ directory, so move the extracted files there:

Move Extracted Sublime Text 3 Files to Opt Directory:
$ sudo mv Sublime_text_3 /opt/

 

Creating a Bash Script to use Sublime Text 3 from the Terminal

Now that we have located the files in an appropriate directory, let's make a Bash script which will allow us to execute Sublime Text 3 with a simple command. To do this, we are going to stay in our terminal, and perform a very simple edit using vi.

First, change to the /opt/sublime_text_3/ directory:

Move into the Sublime Text 3 directory in /opt/
$ cd /opt/sublime_text_3

 

Next, open vi into a new file named subl3 (this is a convenient shortcut to use from the terminal):

Open Vi Into New File suble3:
$ vi subl3

 

If you are new to editing text from the terminal, don't panic, this is not too bad, and also is something you should learn how to do, if only for occasions like this). There are a few key things to know about vi:

  • vi opens in Command Mode – you cant type any text yet. To enter Insert Mode, type the asterisk character followed by capital I ( *I ). This will allow text entry on the current line.
  • To return to command mode, hit the <escape> key.
  • to save the current file, from command mode, type the Colon character, followed by lower-case w and lower case q, then hit enter ( :wq <enter> ).

Now, you should be looking at a blank screen in vi. Enter Insert Mode ( *I ) and type the following two lines:

Type Bash Script Into Vi that Creates an Alias for Sublime Text 3
#!/bin/sh
exec /opt/sublime_text/sublime_text "$@"

 

Then exit Insert Mode ( <esc> ) and save the file ( :qw ).

Congratulations. You have now created a Bash script. Now, let's make sure the access permissions on our script are appropriate. Set the access permissions as follows:

Set Access Permissions on new Bash Script:
$ sudo chmod 755 subl3

 

This allows anyone to read or execute the script, but only the owner can write to it.

Now, we need to move the script file to the /usr/bin/ directory, so that it can properly respond to Bash commands:

Move Script to Proper Directory:
$ sudo mv subl3 /usr/bin/

 

Now, having done all that, let's look at the easier way to accomplish all of the above steps.

Install Sublime Text 3 on Linux Mint /Ubuntu Using Personal Package Archive (PPA)

This is what I consider the better way to do this.

Canonical, the company which supports Ubuntu, has created the Launchpad.net site which, among other things, hosts a repository for Personal Package Archives (PPA's). Here, individuals and teams can upload their own software and installation packages, and it is possible to find deployment packages for software that is not included in the Ubuntu or Linux Mint Synaptic Package Manager for your specific distribution. It is also possible to add the PPA to your Synaptic catalog, so that you can then run apt-get install, apt-get update and the like to keep your package up to date.

Or, at least as up to date as the package maintainer at Launchpad keeps theirs.

The WebUpd8team at Launchpad has created (among other things) a PPA for Sublime Text 3 (currently still in beta as of this writing). To add Sublime Text 3 to your Synaptic catalog, and install according to the install script published with the PPA, follow these steps:

Add the Sublime Text 3 Repository to your Synaptic Package Manager:
sudo add-apt-repository ppa:webupd8team/sublime-text-3

 

Update:
sudo apt-get update

 

Install Sublime Text:
sudo apt-get install sublime-text-installer

 

Next, check the usr/bin directory. You should see a file named subl. This is the alias you can use to invoke Sublime Text 3 from the command line, just like we created manually above.

There you have it. You can now use Sublime Text 3 from you command line. Also, you should see it available in your GUI in the applications menu.

This has been a long post about a relatively simple operation. My goal has been to explain the concepts as fully as possible, under the assumption that there are those out there, like myself, new enough to Linux to need the extra handholding.

In addition, if you first followed the manual instructions, you may have learned a few more of the basics in working with Linux (an vi).

Thanks for reading!

Other Topics of Interest

 

Posted on August 25 2013 10:10 AM by jatten     

Comments (1)

Installing Sublime Text 2 on Linux Mint/Ubuntu (for Linux Newcomers)

Posted on April 23 2013 07:08 PM by jatten in Linux, CodeProject, Learning Linux   ||   Comments (5)

TL:DR – For a newcomer to Linux, likely starting out with Ubuntu or Linux Mint, installing applications that are not part of the Software Manager or Synaptic Package Manager catalog for the chosen distro is not always intuitive at first. I take a rather long look at how to get Sublime Text 2 properly installed on your machine, and do my best to explain what is going on, rather than simply provide terminal entries to copy and paste. I would be happy to hear from experience Linux users about how I might improve, or where I have explained something poorly.

New Article for Sublime Text 3

UPDATE: 8/25/2013: There is now a new article available with slightly different instructions on installing Sublime Text 3, currently in beta but recently made available to the general public. Sublime Text 2 is still the current stable release. However, the version 3 beta seems quite workable.

Also of Interest:

A few months back, I decided to expand my horizons and explore Ruby and Rails. I also decided that I would do so in the more native Linux environment, rather than go the Ruby-on-Windows route. This was one of the best decisions I have made in terms of developing my skills and experience as a programmer.

Sublime_Text_LogoThe learning continues. I started with Linux Mint 13, which has a friendly enough GUI, but for most of what I am doing, I try to use the Bash CLI as much as possible. I've never been very comfortable with the command line, and so long as I am learning a new language, in a new OS environment, I figured it was time to overcome that limitation as well.

If you are an experienced Linux user, there is probably nothing here for you. This is really basic, and yet I had to look around and cull some information from a variety of sources in order to figure out how to do this.

Why Sublime Text 2

Unless you have been in a coma, you have no doubt at least heard of Sublime Text 2. Sublime Text 2 is a cross-platform (Mac/Windows/Linux), highly customizable text editor with an outstanding compliment of features. I have found it to be my preferred, go-to tool for text manipulation. While it is not an IDE, Sublime Text presents sufficient IDE-like features that for many purposes, you won't miss the extra cruft. Also, of course, in many programming communities (Ruby, JavaScript), code is more often written in a text editor.

NOTE: As of this writing, Sublime Text 3 is available to registered Sublime Text users as a beta release.

Sublime Text 2 is not currently part of the Synaptic Package Management system on Linux Mint (or Ubuntu). Therefore, there is no magical apt-get install command as you might use to install other software on your Linux system, so we have to do a little more work.

Installing Sublime Text on Linux Mint/Ubuntu – The First Method

Of course, the straightforward method of installing Sublime Text 2 on your Linux Box is to download the appropriate (23 or 64-bit) .tar file from the Sublime Text site, unpack, and locate in the directory of your choice. You can do this manually by going to the Sublime Text 2 Downloads page and clicking the appropriate download link, or you can do it all from the terminal, as described below.

If you are not as familiar with Bash command line as you would like, see my previous posts. While these were written in the context of using Git for Windows developers, the basic Bash commands are explained:

This method is described on the Sublime Text Site/Support/Linux/Installation page. Simply open a terminal in the directory you use for applications, and enter the following command (use the appropriate version fro your machine):

NOTE: As of this writing, Sublime Text 2.0.1 is the most recent stable release. If the stable release is updated, the URL's in the links below will change, and you will need to copy the updated URL from the Sublime Text site.

Download the Linux 32-Bit Version of Sublime Text 2:
$ wget http://c758482.r82.cf2.rackcdn.com/Sublime%20Text%202.0.1.tar.bz2

 

Download the Linux 64-Bit Version of Sublime Text 2:
$ wget http://c758482.r82.cf2.rackcdn.com/Sublime%20Text%202.0.1%20x64.tar.bz2

 

Extract the "Sublime Text 2.0.1.tar.bz2" file (this will be "Sublime Text 2.0.1 x64.tar.bz2" for the 64 bit version):

Extract the Sublime Text .tar file:
tar vxjf "Sublime Text 2.0.1.tar.bz2"

 

9/10/2013 – UPDATE: It is apparently considered a best practice to locate general third-party applications such as Sublime Text in the root-level /opt directory, something I did not know at the time I wrote this article. I have updated the instructions and example below to reflect this.

Then you can add a sym link to the executable file with a short name for convenience (it seems to be a convention to use the alias "subl" for ease of use from the terminal. The executable file will be located in the extracted Sublime Text 2 directory. For example, if you extracted the .tar contents into the directory /opt then the sublime_text executable will be "/opt/Sublime Text 2/sublime_text" (since there are spaces in the directory name, we need to use quotes around the path).

Add a Sym link:
sudo ln -s "opt/Sublime Text 2/sublime_text" /usr/bin/subl

 

The above method is easiest, but does not leave you with a convenient way to update Sublime Text in the future short of removing the current installation, re-downloading, and re-installing. There is an arguably better method, which relies on the Personal Package Archive system.

Installing Sublime Text on Linux Mint /Ubuntu– The Better Method

Canonical, the company which supports Ubuntu, has created the Launchpad.net site which, among other things, hosts a repository for Personal Package Archives (PPA's). Here, individuals and teams can upload their own software and installation packages, and it is possible to find deployment packages for software that is not included in the Ubuntu or Linux Mint Synaptic Package Manager for your specific distribution. It is also possible to add the PPA to your Synaptic catalog, so that you can then run apt-get install, apt-get update and the like to keep your package up to date.

Or, at least as up to date as the package maintainer at Launchpad keeps theirs.

8/23/2013 UPDATE: As of 7/19/2013 the WebUpd8team also has a PPA for Sublime Text 3 (currently still in beta). If you want to use Sublime Text 3, simply substitute Sublime-Text-3 for Sublime-Text-2 in all of the commands below. Note that if you used the PPA for Sublime Text 2 to install that version, this will replace the version 2 install with the version 3 beta.

The WebUpd8team at Launchpad has created (among other things) a PPA for Sublime Text 2 which is up to date with version 2.0.1 as of this writing. To add Sublime Text 2 to your Synaptic catalog, and install according to the install script published with the PPA, follow these steps:

Add the Sublime Text 2 Repository to your Synaptic Package Manager:
sudo add-apt-repository ppa:webupd8team/sublime-text-2

 

Update:
sudo apt-get update

 

Install Sublime Text:
sudo apt-get install sublime-text


8/23/2013 UPDATE: If you are installing the Sublime Text 3 Beta as discussed in the update above, use this command instead of apt-get install sublime-text:

8/23/2013 Install for Sublime Text 3 Beta (only if using the PPA for Sublime Text 3):
sudo apt-get install sublime-text-installer

 

Next, check the usr/bin directory. You should see at least one file, named sublime-text-2, and you should also see two others, named sublime-text and subl. These create aliases you can use to invoke Sublime Text 2 from the command line. If the subl and sublime-text files are not present, copy the sublime-text-2 file and make them:

Create alias files (if not present):
$ sudo cp /usr/bin/sublime-text-2 /usr/bin/sublime-text
$ sudo cp /usr/bin/sublime-text-2 /usr/bin/subl

 

There you have it. You can now use Sublime Text 2 from you command line. Also, you should see it available in your GUI in the applications menu.

This has been a long post about a relatively simple operation. My goal has been to explain the concepts as fully as possible, under the assumption that there are those out there, like myself, new enough to Linux to need the extra handholding. Thanks for reading!

 

Posted on April 23 2013 07:08 PM by jatten     

Comments (5)

About the author

My name is John Atten, and my username on many of my online accounts is xivSolutions. I am Fascinated by all things technology and software development. I work mostly with C#, Java, SQL Server 2012, learning ASP.NET MVC, html 5/CSS/Javascript. I am always looking for new information, and value your feedback (especially where I got something wrong!). You can email me at:

jatten@typecastexception.com

Web Hosting by