If you haven’t heard of Sublime Text, you
are missing out on what is possibly one of the best text editors available
today. Sublime Text is a simplistic text editor with an uncluttered UI a
beautiful interface, and a powerful keyboard driven interface. It has very rich
keyboard shortcuts that make reaching for the mouse unnecessary. It is also
highly customizable and extensible with its own plug-in API.
Command Palette
Probably the most powerful feature of
Sublime Text is the Command Palette accessible by pressing Ctrl+Shift+P. Think
of it as a command line for Sub-lime Text.
Probably
the most powerful feature of Sublime Text is the Command Palette accessible by
pressing Ctrl+Shift+P.
When you use the aforementioned shortcut,
what you see is a list of commands and their corresponding short-cuts, if any.
The best thing about this list is that it is searchable. If at any point you
want to perform an action, and you do not know the keyboard short-cut for it,
simply open the Command Palette, and start typing the name of the action.
Let’s say you want to convert a sentence
from normal case to title case. Open the command palette and type “case”. You
should see a number of options for converting between different cases.
Install the Package Manager
Installing packages for Sublime Text is
simple enough, and just requires one to copy the package files to the Sublime
Text pack-ages directory. However there is a better way that integrates with
the Sublime Text editor – Sublime Package Control.
Sublime Package Control is a package
manager that allows you to download, install, update, and remove packages
directly from Sublime Text. Of course you need to install the package manager
itself first, but that too is simple enough. Visit http://dgit.in/SHszAWfor
installation instructions.
Sublime
Package Control
Once it is installed, you will notice new
commands for managing packages in your Command Palette. Press Ctrl+Shift+P and
then type “install” and you will see “Package Control: Install
Package” as one of the options. Select it and after a short wait you will see a
searchable list of packages you can install.
Plug-ins
Now that you have the package manager,
there are a few plug-ins you just need to install:
·
Prefixr: If you work a lot with CSS, this
plug-in is a must have. It automatically adds the correct browser prefixes to
CSS properties.
·
Sublime Alignment: This neat plug-in allows you
to automatically align your code to the same indent level or align assignments
around the “=”
·
SFTP: If you want to work on code directly on a
remote FTP server.
·
Bracket Highlighter: Automatically highlights
starting and ending brackets around a code segment.
·
Emmet: Formerly known as Zen Coding, this is a
highly condensed way of writing HTML or CSS code.
·
Omni Markup Previewer: If you want to use
light-weight markup languages like Markdown or Textile, this plug-in is must
have. It exports such mark-up to HTML and shows a live pre-view in your
browser.
·
Code Intel: This plug-in adds support for code
auto-completion, function call tool-tips, and jump to definition, bringing it
closer to an IDE.nettuts+ Fetch: If you routinely need to work with remote
files, this is a handy package. Just configure your popular remote files, and
this package will fetch the latest version for you whenever you want.
·
Color Picker: This allows you to tweak CSS colors
with a handy color picker.
·
Sublime REPL: This gives Sublime Text an inbuilt
REPL or Read Evaluate Print Loop or in other words interpreter. It supports a
number of languages, from Python and JavaScript to F# and R.
·
Gist: If you use GitHub, the Gist plug-in will
come handy as it allows you to quickly publish some code from a local file to a
Gist. Once you have the package manager installed, just search for these
packages using that and install them if you want. There are nearly a thousand
packages available for Sublime Text that do everything from adding support for
specific frameworks, adding support for VCS systems, changing the theme or color
scheme, automatic Linting, adding support for more languages, and lot more.
Edit at multiple points
Another powerful feature of Sublime Text is
multiple cursors. With multiple cursors active, you can type the same text in
multiple locations at the same time.
To use multiple cursors, simply click in
multiple places in your document while keeping the Ctrl key pressed. Wherever
you click, a new cursor will be added, and any text you type now will
simultaneously appear in all those places.
A keyboard shortcut for this is also
available, press Ctrl+Alt+Up or Ctrl+Alt+Down to add another cursor at the same
column in the line above, or below respectively. To get rid of multiple
cursors, and switch back to a single one as you would obviously want to do at
some point, just press Esc.
Multiple Selections
Just like you can have multiple cursors,
you can have multiple selection as well, which let you modify multiple places
at the same time.
Multiple
Selections
The process of making multiple selections
is simple. If you have some text selected, and you would like to select more
text elsewhere, just drag and select that text while keeping Ctrl pressed.
This feature is a lot more powerful though.
Let’s say you realize after writing a lot of text that you spelled ‘color’ as ‘color’
and you were supposed to use the British spelling? Simply put your cursor over ‘color’
and press Ctrl+D; this will select ‘color’ and highlight other instances. Now
keep pressing Ctrl+D till all or as many as you want instances are selected.
Then simply type in the replacement.
Modifying settings
You may find that Sublime Text doesn’t
really have a settings panel like you might expect. There is no GUI for
configuring the software, but what you do have is a rich set of configuration
files that let you alter nearly everything about the software.
In the Preferences menu, you will find
entries such as Settings – Default and Settings - User. Altering either of them
will change the desired setting, but only the User set-tings will survive an
update to a plug-in or of Sublime Text.
By default many “User” set-ting will be
blank, but you can open the “Default” versions of the config files to see what
set-tings are available to configure. If you want you can just copy-paste the
contents of the default file in the user file and only modify the settings you
want. This is recommended because this file has to be in a very specific format
called JSON.
The settings are terse variable names, but
the names are often self-explanatory. For example: “spell_check” sets whether
Sublime Text automatically highlights spelling mistakes by default, you might
want to enable it if you mostly work with non-code text; “highlight_ line” sets
whether the line(s) containing a cursor should be highlighted. Most plug-ins
will have their own setting, which too will be divided into default and user.
Change the theme
The default UI theme is pretty good, but
you may have your own preferences, and luckily for you the theme can be
changed. Installing a theme is simple thanks to the package manger, just search
for “theme”. Switching themes however, requires you to edit the configuration
files.
Select Settings - User from the Preferences
menu. As we said before, this file uses the JSON format, if you don’t know what
that is just copy the everything from Settings Default and make changes to
that, we’ll assume that is what you have done.
Switching
themes however, requires you to edit the configuration files
Find the line that says “theme”,
which by default is set to “Default.sublime-theme”. Change this setting based
on the theme you installed. Try it with the popular “Soda” theme. Install the
Soda theme using the package manager, and then change this setting to “Soda
Light.sublime-theme” for the light version of the theme, or “Soda
Dark.sublime-theme” for the dark version.
Color Scheme
Like the theme, the syntax highlighting
scheme used by Sublime Text can also be changed. Like themes, you can find
color schemes using the package manager. Just search for scheme and you should
see many of them.
Sublime Text has a simple UI for changing
color schemes; they are all listed hierarchically under Preferences > Color
Scheme. Some themes also include color schemes that fit with that scheme.
Make a plug-in
If all else fails you can always make your
own plug-in for Sublime Text. You will notice that the Tools menu has a New
Plugin...option. SublimeText plug-ins are written in Python, so you will need
to know that a bit in order to do something useful. You can check out a
tutorial here: http://dgit.in/149A1bt.