This page has been robot translated, sorry for typos if any. Original content here.

Sublime Text 2 FAQ

On this topic:


Sublime Text 2 FAQSublime Text 2 FAQ

A couple of months ago, I accidentally stumbled upon a lot of positive feedback about the text editor Sublime Text 2.

Having tried it in business, I was not disappointed. Now this is my main work tool.

Sublime Text 2 is a paid text editor written in C ++, which:

  • Runs on Linux, OS X and Windows
  • It has a decent speed
  • Nice interface (including all kinds of animations)
  • Flexibly customizable (though not in the GUI, but in the json-configs)
  • It has many plug-ins, the number of which is growing by leaps and bounds
  • Supports VIM mode
  • Uses fuzzy search

Activation and prohibition update

All you need to do is go to Preferences -> Settings - User and add the following line there:

"update_check": false

You can also block the update site via the hosts file , just add the following text:

## STOP SUBLIMETEXT UPDATES
127.0.0.1 sublimetext.com
127.0.0.1 www.sublimetext.com

Price

Shareware or shareware editor :) It costs $ 59 for a license (if you take a lot at once, there is a discount), but you can use it for free. In the free mode, once a couple of hours, a dialog box pops up with a suggestion to purchase an editor, and caps is written in the caption of the window at UNR right. As far as I know, there are no other differences.

Interface

Sublime Text 2 FAQSublime Text 2 FAQ

One of the first impressions of the program is that it is beautiful out of the box. Correctly chosen fonts, color scheme, smooth animations (there are more of them than in most text editors and IDE). All this makes sense, because in the end, it pleases the eye and does not distract attention. As long as the editor is not overloaded with plug-ins, it has a very fast response, which I managed to get rid of using NetBeans.

The first thing that catches your eye is the absence of any toolbar. Also, I have not yet encountered a single dialog box, except for the standard windows for saving / opening a file. Instead of dialog boxes, “layers” are used. Space characters and tabs are displayed only when text is selected, but in the settings you can set the “always” mode.

Right on the board is a code card . A peculiar analogue of scrolling a page in the form of a pixel-map, which is the code of the current file compressed to ~ 100px horizontally (including syntax highlighting). Helps to navigate through the file, and also makes it easier to scroll the page, because acts like a scrollbar. It is difficult to say “killer feature” or the next “whistle”, but during the whole period of use I didn’t have a desire to remove it.

On the left side of the board can be a panel of the project and open files (View -> Side bar -> Show side bar). Project panel - a tree of directories connected to the project with simplified file manager features (for example, you can create new files / folders, rename and delete, but there is no possibility of moving #UPD turns out to be, through renaming). The open file panel did not seem to me to be too much or too much duplicating the functionality of tabs. Tabs are more familiar, but when there are too many of them, it is easier to find the one you need by name in this panel.

Full-screen mode (F11) and " Distraction Free Mode " (Shift + F11) are available. With the first, I think everything is clear, but the second was new to me. This mode is a full-screen mode with its own settings. For the first time going into it, only the code editor itself and the menu bar are available to you. In it (in -> View) you can enable / disable all the necessary / extra. Convenient mode for deep immersion in work.

Vertical selection mode is one of the most important functions for advanced text editors. And sublime is no exception. In the Linux version, it is activated by the right mouse button while the cipher is clamped. Very handy for quick edits of various kinds of lists, markup and more. It should be noted that ST2 is able to search and replace by regular expressions, without which it would be difficult to consider it seriously.

Also worth mentioning is the horizontal scroll . If your mouse doesn’t have it, use shift + vertical scroll. As it turned out - very convenient. In the status of the panel, in addition to errors and the current cursor position, the switches of the current file syntax and tab-a size are available.

Button icons for expanding / collapsing code regions (functions, blocks, tags, etc.) are somewhat unclear. The fact is that although they are located, as they should, to the left of the line of code, but, by default, they are displayed only by mouseover (this is configured). Available for many structures, in particular, very pleased with the possibility of "folding" SCSS-selectors.

Sublime provides plenty of options for multiple selection and editing . Those. You can set the cursor in several places at once and edit the code synchronously (macros, autocomplete, snippet, clipboard, etc. will work at the same time). I really missed this in Netbeans. You can set a new cursor position via ctrl + left_mouse_click. Or ctrl + left_double / _triple click (selects the entire word / paragraph). These and other shortcuts and mice are flexible and customizable.

Fuzzy search

Sublime Text 2 FAQSublime Text 2 FAQ

One of the most advertised functions of the editor is fuzzy search. It allows you to find “modules / gallery / view / gallery / page.jade” by typing only “gapaja”. To say that it saves time is the same as not saying anything. In 99% of cases, I open the files or find the function I need in this scraps, resembling some East Asian dialect :) Out of the box are available:

  • Ctrl + P - search in project files
  • Ctrl + R - search by function (by template-s in XSLT, selectors in CSS / SCSS, etc.)
  • Ctrl + Shift + P - search through the menu (and new functions from plug-ins get into it, i.e. it is not necessary to remember the hotkeys for rarely used features)
  • Ctrl +; - search by words. For example, by driving dbr, you can find where you forgot to remove the service debugger in the js file
  • Ctrl + G - line number (not fuzzy-search, but, I think, this is where it belongs)

After playing with these combinations, you can pay attention to the fact that these modes can be combined. For example, having hammered in the gapaja @ gallery_list, we will get not to the beginning of the file, but directly to the mixin-gallery_list.

This list can be expanded with plugins. About a couple of these, I will discuss below.

Configuration

All settings are made through editing json-configs. Changes take effect immediately after saving the file. Most of the settings that you can get (whether the editor itself or its plugins) are divided into 2 parts - default and user. Those. the end user should change user-configs, which by default are usually empty.

You can see the basic editor settings by selecting Preferences -> Settings-Default in the menu. I will run on the most key:

  • word_separators is an expression for word separation. For example, to double-click on a PHP variable, it would stand out with $, this option can be corrected like this - "./ \\ () \" '-:,.; <> ~! @ #% ^ & * | + = [] {} `~?"
  • fade_fold_buttons - display fold-icons (opening / hiding regions of code) only when you hover the mouse
  • tab_size, translate_tabs_to_spaces - tab-a size and the ability to use spaces instead of tabs
  • folder_exclude_patterns - an array of masks for files / directories that will be ignored when working on projects
  • trim_trailing_white_space_on_save - trim leading spaces when saving
  • show_tab_close_buttons - show "crosses" on tabs
  • draw_white_space - show space and tab characters always or only when text is selected
  • save_on_focus_lost - automatically saved when another file is selected or the editor loses focus
  • default_encoding - the default encoding is “UTF-8”
  • fallback_encoding - the encoding in case it was not possible to determine automatically
  • auto_complete - on / off “autocomplete”. Since ST2 is not IDE, then autocomplete out of the box works on the principle - “here's all the words on the page, choose what you want.” Many don't like it
  • hot_exit - by default, the editor is closed without confirmation of saving / non-saving changed files. It simply remembers their condition and opens as if it did not close at all. The same behavior when switching projects. This option allows you to set the standard mode.
  • close_windows_when_empty - close the program when closing all files
  • preview_on_click - by default, when a file is selected in the project tree, it does not create a separate tab for it, but simply shows it over the current file. You can make a couple of changes and save. If you want to open the file "full", then you need to double-click. This option is responsible for this behavior.

This is not all settings, but only those that I encountered or seemed to me the most important for beginners. Options like preview_on_click, hot_exit may scare, but I would recommend trying them out.

Hotkeys

Sublime Text 2 FAQSublime Text 2 FAQ
Detailed map of hot keys Sublime Text 2 FAQ

Hotkeys change according to the same principle as all other settings, and also take effect immediately after saving the config. In the case of any error, such as the wrong key combination, you can find out the details in the console (Ctrl + `). There you can find a lot of useful data.

I think it makes no sense to go deep into the settings of the keys. they are intuitive. For example, the following "bandage":

  {"keys": ["ctrl + e"], "command": "run_macro_file", "args": {"file": "Packages / Default / Delete Line.sublime-macro"}} 

Runs the Delete Line macro when pressing Control + E. And this:

 {
  "keys": ["ctrl + shift + o"],
  "command": "fuzzy_file_nav",
  "args":
  {
  "start": "/ www",
  "regex_exclude": [". * \\. (DS_Store | svn | git) $"]
  }
 }

Runs the fuzzy_file_nav command (ext. Plugin), with arguments. Perhaps you will help my config gor.klavish. The mouse can also be configured - for this there are .mousemap. Unfortunately, I could not find any detailed documentation about these files.

Work with projects

If you use the editor instead of the IDE, it is quite difficult to do without projects. Initially, you are working on the “default” project, and in order to create a new one, select “Project -> Save project as” in the menu. You will be prompted to specify the path for the project config file. After creating a project, you should attach working directories to it (most often it is one, but you can specify several). To do this, select “Project -> Add folder to project”, after which it will appear in the panel on the left (provided that you have enabled it). From now on you will have a fuzzy project search (Ctrl + P).

Let's move on to setting it up (Project -> Edit project). In it you will find the hooked directories. To exclude too much from them, add folder_exclude_patterns : ["path_1", "path_2", ...] and file_exclude_patterns : ["* .md", ...]. Changes, as usual, will take effect immediately after saving. Now searching in files and fuzzy-searching by file names will ignore the unnecessary, and the tree of files on the left will thin out a little. In the same config file, settings for some plugins can be set. For example - xdebug. More information you can get here .

Switching between projects is very fast, which made me very excited after NetBeans. By default - Ctrl + Alt + P. The editor remembers the list of open files, the active tab, the position of the cursor and scroll. You can also open a new window (not a tab, Ctrl + Shift + N) of the editor and set another project there.

Plugins

No text editor of this level can do without plug-ins. You can install the plugin simply by copying it into the sub-directory User. The easiest way to find it is Preferences -> Browse packages. You will have a file manager in the installed plugins directory. As you can see a lot of them :) However, there is a simpler and more correct way (for most situations) - use PackageControl. About him a little lower.

The main language of writing plugins is python. That's probably why there are so many of them. If you are interested in this topic, you may need this article .

PackageControl

Its installation is not very obvious. First, go to the page of the plugin . We press the green install button and get to the page with detailed installation instructions. At the time of this writing, it consists of copying a piece of python code to the editor console (Ctrl + `) and pressing the enter key. You ask - what a terrible shamanism? Do not worry, on this surprises are over. Then everything will go like clockwork (provided that the PackageControl is normally installed). I hope the developers will add it to the base build.

Sublime Text 2 FAQSublime Text 2 FAQ

You can call the PackageControl “layer” from the Preferences -> Package Control menu. But simpler is ctrl + shift + p, and then type the necessary command. For example, to access the “Install Package” I had three characters - “ins” in a fuzzy search. How did I live without him? :) The module itself is extremely obvious, therefore, I believe, it makes no sense to paint it in detail. I will only note that some plug-ins have their own configs or city keys. In this case, quick access to these settings can be obtained using the Preferences -> Packages settings ->% plugin_name% menu.

A small selection of plugins

Aligment - allows you to format configs / arrays / anything so that the values ​​are located at the same level horizontally. Not very convenient thing, but better than nothing. First you need to set the cursors before each value, and then press "Ctrl + Alt + A" (in the Linux version).

FileDiffs - allows you to compare two files for differences. Adds the “FileDiffs Menu” and “Diffs with tab” options to the tab menu, as well as a couple of items to the context menu of the editor itself. The result opens in a separate tab and, as expected, highlights the lines in green and red. If nothing is opened, the files are identical, which will be indicated by a message in the statusbar.

FuzzyFileNav - Allows using fuzzy search to open a file outside the project, running through the file structure. Not as cool as in Ctrl + P, but, for me personally, it’s much more convenient than in the standard OS dialog box.

FileHistory - fuzzy search on recently opened / closed files. Used before I found GotoOpenFile.

GotoOpenFile is a copy of the Ctrl + P mode, but only applies to open files.

JsMinifier - allows you to pack selected (or the entire code of the current file) javascript. The plugin uses Google Closure Compiler and UglifyJS. If nothing happened - look in the statusbar, most likely the javascript code is not valid.

PhpDoc is a simple PhpDoc assistant. To use it like this: write / ** [tab]. Already inside - [dog] var [tab], [dog] return [tab], etc. Automatically determine the types and names of variables and other useful things can not, but it inserts * when translating the carriage :)

GotoTab - allows you to switch tabs by pressing Ctrl + [numbers]. Pretty handy thing.

SublimeLinter - on-the-fly syntax checking (or as configured). Able to cook - CoffeeScript, CSS, Java, JavaScript, Objective-J, Perl, PHP, Python, Ruby. Uses ready-made tools. For example, for JavaScript, it offers a choice between JsLint, jsHint and gjslint. jsHint, which is the default, does not just check the syntax, I impose my true-coding-style on you, which you can partially configure in the config. I did not have enough, because the library was not as flexible as it should be, therefore it was necessary to use surgical methods :) It is also worth noting that SublimeLinter is able to make your editor freeze. In this case, rummage through the settings, it is quite flexible to configure.

Tag is a library that provides convenient tools for working with XML. I use to bring XML to a readable form. Of course, on this his possibilities are not limited. For example, by typing “div” and pressing ctrl + shift + "," I get <div> </ div> with the cursor inside.

XDebug - the xdebug debugger. Not very comfortable. Debugging in NetBeans is much more convenient. However, for simple tasks it can be useful. Users * buntu be sure to read the section "Troubleshooting" on the page of the plugin.

LastEdit is a buggy analogue of ctrl + q in Netbeans. Moves the cursor to places of recent changes. Very handy thing, but, unfortunately, often does not work. If you are interested in this feature, you may want to try this plugin .

A more complete list is available here . But far from all the plugins that I came across are in it.

Syntax highlighting out of the box is quite extensive. However, for nginx and apache2 configs, I needed SCSS and Jade to install plugins. If you didn’t find such a plugin for the language you are using, try porting the highlight from Textmate, since many things are supported as native ones.

Snippets

Snippets are pre-prepared pieces of code, with anchors arranged in them. Those. instead of writing <xsl: when test = "some"> some code </ xsl: when> you can write snippet. I will give a simple example:

	 <snippet>
	  <content> <! [CDATA [for (var $ {1: name} in $ {2: source}) if ($ {2: source} .hasOwnProperty ($ {1: name}))
	 {
	  var $ {3: iterator} = $ {2: source} [$ {1: name}];
	  $ {0: // code}
	 }]]> </ content>
	  <tabTrigger> forin </ tabTrigger>
	  <scope> source.js </ scope>
	  <description> for (var name in source </ description>
	 </ snippet>	

tabTrigger - the line that you need to type and press tab (it is not necessary to fully type, because Snippets get into autocomplete). After activation, the cursor moves to $ 1 and highlights “name”, the next pressing of the tab will highlight the source, which will change in 3 places at once. At the end of the snippet, you will get $ 0. To stop his work ahead of time - you need to press Esc . Unlike Netbeans, I was able to set all the Snippets I needed without any problems with “jumping up” the cursor to the beginning of the file, a jumble of indents and other incomprehensible behavior (if the reader wants to call me “curved”, I can give an example of such behavior :) ). Scope - determines the type of files in which snippet will be used, and you will see the description in autocomplete.

More information can be found here . Perhaps a selection of snippets will help you.

Macros

Macros and in Africa - macros. You can start recording through Tools -> Record macro, stop - there. When finished, it should be saved (Tools -> Save macro) in the Packages / User directory. Opening the final file, you will see a json-array with a list of actions performed. You can set a hotkey for a macro using the following syntax: {"keys": ["alt + 1"], "command": "run_macro_file", "args": {"file": "Packages / User /% your_macros% .sublime- macro "}}.

Layouts

The fact that there are layers in ST2, I learned quite recently, after seeing the screenshot on lor . Layers allow you to divide the editor window into several parts (2, 3, grid, etc.). This is very convenient when you write something in one file, relying on the contents of the second. But with my 19 "square" monitor, this feature does not look very attractive. Unfortunately, you cannot open different projects in different layers. It is also worth noting that the open file panel (which is on the left), after turning on the multi-layer mode, is divided into several groups .

Conclusion

Sublime Text 2 is a great choice for a programmer or administrator. For the average user, in my opinion, an editor without json-configs and with a more obvious GUI would be more suitable.

It is important to understand ST2 - a text editor, not an IDE, although, using third-party plug-ins, it can be somewhat closer to this status. True, I never managed to start a smart autocomplete .

Было много критики в сторону NetBeans, но я бы хотел отметить, что эта IDE мне нравится, и я до сих пор ей пользуюсь, хотя и крайне редко (к примеру, для отладки nodeJS или PHP-xDebug). Мне очень не хватает в ST2 столь же удобного средства для «патчинга» файлов, просмотра предыдущих версий, документации и разного рода вкусных штук, присущих IDE, вроде перехода к определению функции при нажатии ctrl + left_click, даже если файл находится чёрт знает где. Однако ST2 дал мне куда большую лёгкость и удобство при решении рядовых задач.