Sublime text 3 utf 8 encoding. How to turn Sublime Text into the perfect text tool

Sublime text 3 utf 8 encoding. How to turn Sublime Text into the perfect text tool
Sublime text 3 utf 8 encoding. How to turn Sublime Text into the perfect text tool

This is a text editor that you will fall in love with, as its creators say ( Sublime Text: The text editor you'll fall in love with) . The statement is bold, but it is difficult to disagree with it: many have fallen in love with this product. There are many reasons: cross-platform, plugin support, incredibly thoughtful multi-selection, nice appearance and much more - to each his own. But even in this barrel of honey there was a place for several grams of tar, but it can be pulled out without any problems. How - here you will find out.

The settings for everything and everything in Sublime Text are stored in JSON format, the main settings can be called up through the menu " Preferences - Default". Through "Preferences - User" you can see the user settings. That is, by configuring Sublime Text once, you can save these settings to yourself and restore each time after installation on any computer - this is convenient. A description of each setting is attached - this is also convenient. Well, more about tar.

Encoding

Encoding problem- everyone whose project is written in win1251 encoding faces it. The program automatically detects ASCII, UTF-8 and UTF-16 encodings, the rest are set to "Western (Windows 1252)" by default, which leads to a sad Cyrillic type like this - ß ãðóñòíàÿ êèðèëëèöà . The "fallback_encoding" setting is responsible for the encoding that is set when it is unsuccessfully determined, by default it is, as mentioned above, "Western (Windows 1252)". There are two options for changing the settings: either overwrite them in default settings, or add to custom. The second is preferable, and the last paragraph says why. Well, in fact, we will use the second option and proudly add a value to the user settings:

"fallback_encoding" : "Cyrillic (Windows 1251)"

Do not forget that the settings are stored in JSON format, so if you make syntax errors, you will enjoy a window similar to this:

You can find out the current file encoding different ways, there are special plugins (for example, the Encoding Helper package), but I prefer the option of making it myself. An example of writing such a simple plugin can be found in another article (in the process of writing, the link will be here).

Hotkeys

Lacks hot keys for habitual or frequently used actions? It doesn't matter - almost everything is configurable in Sublime Text! So we call the menu item "Key Bindings - Default" and study the contents of the opened configuration file. It's still the same JSON we know. Here is an example of one of the simplest hotkeys:

( "keys" : [ "ctrl+s" ] , "command" : "save" )

Everything is clear intuitively - keys and command. How to find out the name of the command you want to assign hotkeys to? It's simple - open the console (Ctrl+` or View - Show Console ) and enter the command:

sublime.log_commands (True)

Now we see in the console all the operations carried out in the editor. For example, let's add hotkeys to convert text case to header ( Edit - Convert Case - Title Case). Command output is enabled, so we call this menu item and look at the console. We see:

command: title_case

All settings in Sublime Text are divided into default and user settings, key settings are no exception. Therefore, we call "Key Bindings - User" and write the settings there. The command is known, the question remained in the keyboard shortcut. There are a lot of busy combinations (there are 250 of them in Sublime Text 2), so before using the combination you like, check if it is already used - combinations from the user set overwrite the default ones. Poking around, we find an unoccupied combination and write to the settings file:

[
( "keys" : [ "ctrl+alt+shift+t" ] , "command" : "title_case" )
]

You do not need to restart the editor - it picks up all the settings on the fly when saving. So we open some file, select a word or put a cursor in it, press our favorite keyboard shortcut "ctrl + alt + shift + t" and see that our work was not very in vain.

Comments are supported so that temporarily unnecessary actions can be commented out:

[
// ( "keys": ["ctrl+alt+shift+t"], "command": "title_case" )
]

Color scheme

Many face uncomfortable color scheme, it's even easier to change.

The most classic scheme is "iPlastic". All schemes are separate files, have *.tmTheme extension and are an XML file. So they can be edited, downloaded, substituted, shared, etc. They are (for example, the second version of Sublime Text) in the folder " %USERPROFILE%\AppData\Roaming\Sublime Text 2\Packages" for windows, " ~/.config/sublime-text-2/Packages" for Linux and " ~/Library/Application Support/Sublime Text 2/Packages/ for OS X.

Plugins

A lot of plugins have been written for Sublime Text, they are available through the menu Preferences - Package Control. If you do not have this menu item, then read the installation instructions, which is located at this address.

Creating a simple plugin

Let's set ourselves the goal of displaying the current file encoding in a pop-up window using a keyboard shortcut Shift+F1. To get started, run the command Tools - New Plugins and in the resulting file paste:

import sublime, sublime_plugin
class EncodeAlertCommand(sublime_plugin.TextCommand ) :
def run(self , edit) :
sublime.message_dialog(self .view .encoding() )

Yes, Sublime Text plugins are written in Python.
Function self.view.encoding() returns the current file encoding. You can check the result in the application console by running view.encoding().
Function sublime.message_dialog(string) calls a dialog box with text string inside.

It remains to set the method hot key: Preferences - Key Bindings - User. Add an element to this JSON:

( "keys" : [ "shift+f1" ] , "command" : "encode_alert" )

To check, open the file of interest and click Shift+F1.

Sublime Text, as they say, is a more elegant text editor for more civilized times. Many authors and readers ][ use it to work with code, layout and configs. But how to use it to work with "human" texts? I'll tell you a secret - almost the entire editorial staff of the magazine uses it every day to work on articles, and during this time several convenient hacks have accumulated. In this article I will tell you how to turn ST into perfect tool for such work.

Why not use any other text editor? The answer is simple - why produce entities? Sublime Text is packed with useful features that iA Writer and other fancy Markdown editors (not to mention monstrous Word) don't have. From the obvious: code coloring, auto-completion, document mini-map, heading collapse, built-in terminal and a huge collection of plugins. Finally, the ability to sort lines and multiple editing, in which you place several cursors in the text at once and make the necessary edits. Any operation can be performed without taking your hands off the keyboard, it is also easy to connect a lot of external instruments you need. And there are so many customization options that you can deal with different plugins for days on end.

Package manager


Of course, all ST users know about the package manager, but if you are reading this article and are thinking about trying this editor for the first time, then you need to make a small introduction. Package management is a familiar thing for Linux users, as well as for Ruby or Python programmers. However, a text editor that requires a package manager... isn't that too hardcore? In fact, Sublime Text 2 plugins can simply be copied (or cloned with Git) into their intended folder and they will work. But the add-on with the speaking name Package Control simplifies this process even more. It itself is also installed in a not quite ordinary way: you need to open the Sublime Text console and copy the code from the site that activates the installation. Restart Sublime Text, click (in OS X) to open command line(this is not the same as the console!), write install and press Enter. Before us is a directory with plugins. Now just type the name of the desired one and press Enter again. It will download and install automatically. In most cases, you will then need to restart the program. The Package Control item will also appear in the Sublime menu, which opens access to other important features: updating and uninstalling packages are important first of all.

Markdown


We told you about Markdown back in September 2012 (article “Meet. This is Markdown”). This is the best text format ever invented - a simple markup language that allows you to quickly arrange any necessary elements (headings, links, illustrations). All tags are some kind of symbols, so the spell checker will not swear at them and they will not interfere with reading and editing the document. Again, Markdown supports countless blog engines, editors, and other applications. In general, a lot has changed since 2012 - we have implemented a special script that allows you to convert an article in Markdown to Adobe InDesign layout, and now all articles in the magazine that you hold in your hands are accepted only in it. This saved a lot of time for both authors and designers.

For the syntax, visit the site of the language's creator, John Gruber. Another interesting tool is the additional markup tool CriticMarkup , which allows you to mark up comments and corrections in a document. To make it all work in Sublime Text, the MarkdownEditing plugin comes to the rescue.

After installing Package Control, this plugin is installed with one command: just open the editor console, type install and select MarkdownEditing. In one fell swoop, you'll turn a coder's weapon into the ultimate writer's tool. But the plugin not only adds code highlighting, but also changes the appearance of the editor. A light theme will appear, reminiscent of typewritten pages, and line numbers and command completion will be disabled. Important note: MarkdownEditing will only be enabled for files with a specific extension. To influence this, type MarkdownEditing in the console and select the item with the config. You will need to add the following lines to it:

( "extensions": [ "md", "mdown", "txt" ], )

There are other plugins for Markdown that have other useful features. The author of SmartMarkdown, for example, claims the ability of his plugin to collapse blocks of text marked with a heading, just as Sublime can collapse code. However, this mode of operation will conflict with MarkdownEditing. But there is another useful feature- output of the article in PDF. To do this, you need to install the pandoc interpreter on the system and specify the desired path in the MarkdownEditing config.

Spellchecking

Out of the box, Sublime Text only supports English spell checking, but this is easy to fix: just download the dictionaries borrowed from OpenOffice and follow the simple adaptation and installation procedure described on the GitHub page.

For OS X users, there is an even better way - the CheckBounce plugin, which allows you to use system check spelling. Not to say that the built-in OS X check is good, but with each version of the system it is getting better and certainly not inferior to OpenOffice dictionaries. Plus, if you often add some words to the dictionary, then it is convenient for Sublime Text to pick up all these changes.

Another disadvantage is that the list of replacement options is not shown in context menu by right click. Instead, you can put the cursor on the misspelled word and press .

Word counter

Those who work with text professionally and get paid for the number of characters or words (like the authors of The Hacker, for example) cannot imagine life without a character counter in a text editor. But even when writing text for your blog, the indicator of the number of characters can be useful as a guide - it is often important to fit into the size of a particular block in the layout. The plugin that sets the counter in the Sublime Text statusbar is called WordCount . With the default settings, the number of words will be displayed all the time, and there will also be an interesting opportunity to see the number of characters in current line(i.e. paragraph). If you need to have before your eyes the length of the entire document in characters, then you can open the WordCount settings file and write:

( "enable_count_chars": true )

Word highlight

Tautology is one of the main problems that haunt the authors of texts. Sometimes memory fails us and we forget that we just used a word. You can drill paragraphs with your eyes, trying to determine if it has been recently encountered, or you can install the WordHighlight plugin and, by clicking on words, see them highlighted throughout the document. Aha! In the previous sentence, two words "can"! It's okay, it's the author's idea.

Clickable links

It's a good idea to complement Markdown syntax highlighting with another plugin - ClickableURLs . From the name it is clear that it should make clickable hyperlinks found in the document. Unfortunately, it's not that simple: apparently, Sublime Text's APIs don't allow plugins to perform such complex tricks (at least without breaking other functions). So the authors of the add-on got out by implementing the ability to open links when the cursor is placed on them and a certain key combination is pressed. On Windows and Linux it is , in OS X - .

Autodetect encoding

The Encoding Helper plugin is designed for automatic detection file encodings. Initially, SublimeText opens all documents in Windows-1252 Western encoding, and it turns out that old files saved in Windows-1251, DOS or KOI8-R will look incorrect. The Encoding Helper in such cases guesses the required encoding and displays a message in the status bar telling you what encoding is being used and what it most likely should be. The conversion is not performed automatically, but an item will appear in the Edit menu that allows you to convert the document to Unicode from the encoding determined by Helper. If he determined incorrectly, you can independently select the desired encoding from its menu.

Clipboard History

Often, when copying text, the thought is spinning in my head, is there something valuable already on the clipboard that needs to be pasted somewhere before using the clipboard again. Many specialized utilities that work not only with Sublime can get rid of this burden. However, such a plugin also exists - it's called Clipboard History . It works very simply: press the combination (or wild in OS X) and see all the previous entries that fell into the clipboard. Choose any and paste it into the text. To not open the menu, you can press (on poppies) and immediately insert the entry that preceded the current one.

to-do lists


Productivity experts say: you need to write things down somewhere and don’t try to keep them all in your head! Sublime Text will help out here too, especially if you provide it with the PlainTasks plugin. After installing it and restarting Sublime, the first step is to open the PlainTasks help. It explains in detail how to create new cases ( or depending on the system), mark them as completed or canceled, tagging them, and so on. The main disadvantage of this plugin is that you can't just click on the box in front of the line to check the box. This is where we once again run into the limitations of Sublime plugins.

Among other things, PlainTasks replaces Clickable URLs by adding its own keyboard shortcut to open links. Advantageous difference: links to files on the hard disk will also work, and you can point directly to the desired line. Indispensable, especially considering that cases can be directly linked to files in this way.

Novice users and developers may have problems with encoding in sublime text 3. This problem is most often expressed in hieroglyphs instead of symbols. This is possible when the file was saved in the old windows-1251 encoding, which is no longer used for html files, php etc. This is easy to solve in a couple of minutes.

How can I find out the current encoding of a file?

The first way to find out the encoding is through the console, press Ctrl+` or View -> Show Console and type the following command in the console view.encoding() .

The second option is to add "show_encoding": true in the user settings. Go to Preferences -> Settings and add a setting.

The encoding will be displayed in the status bar ( status bar), if you can't see it, turn it on via View -> Show Status Bar

Sublime text 3 how to change encoding?

To change the encoding, you must reopen the file or resave it. The first option is to save the file again through File –> Save with Encoding from the list, select utf-8, after that you need to close and open the file.

We can also do similar actions through File –> Reopen with Encoding .
After these steps, the problem should be fixed.

There is a second option, which is to use the EncodingHelper plugin. I personally did not use it, as there is no need. If you have a desire, you can try.

Plugin Features:

  • Specifies the file encoding.
  • Shows the encoding in the status bar.
  • Converts from UTF-8 to a list of encodings that are in the menu.
  • Converts to UTF-8 quickly from current encoding via menu.
  • Automatically converts to UTF-8 when opening a file using certain encodings, in user options./li>

Encoding issues in the sublime text 3 editor are not as scary as they seem at first glance. I hope the article helped you. If necessary, write in the comments, I will be happy to help.