Sublime text 3 file encoding. How to turn Sublime Text into the perfect text tool. Creating a simple plugin

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, php, etc. files. This can be easily solved 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 -\u003e Show Console and print the following command view.encoding () to the console.

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

The encoding will be displayed in the status bar, if you cannot see it, enable it via View -\u003e Show Status Bar

Sublime text 3 how to change encoding?

To change the encoding, you need to reopen the file or re-save. The first option is to re-save the file via File -\u003e 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 -\u003e Reopen with Encoding.
after these steps, the problem should be corrected.

Another option is to use the EncodingHelper plugin. I personally did not use it as it is not necessary. If you have a desire, you can try.

Plugin features:

  • Defines file encoding.
  • Shows the encoding in the status bar.
  • Converts from UTF-8 to a list of encodings that are on the menu.
  • Converts to UTF-8 quickly from the current encoding via the menu.
  • Automatically converts to UTF-8 when opening a file using certain encodings in user settings. / Li\u003e

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

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). This is a bold statement, but it's hard to disagree with it: many people love this product. There are many reasons: cross-platform, plug-in support, incredibly well-thought-out multi-highlighting, nice appearance, and much more - for each his own. But in this barrel of honey there was a place for several grams of tar, but it can be pulled out of there without any problems. How - here you will find out.

The settings for everything and everyone in Sublime Text are stored in JSON format, the main settings can be called through the "Preferences - Default" menu. Through "Preferences - User" user settings can be viewed. That is, having configured 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, further on about tar.

Encoding

Encoding problem - everyone whose project is written in win1251 encoding encounters it. The program automatically detects the encodings ASCII, UTF-8 and UTF-16, the rest are set to "Western (Windows 1252)" by default, which leads to a sad look of the Cyrillic alphabet like this - ß ãðóñòíàÿ êèðèëëèöà ... The "fallback_encoding" setting is responsible for the encoding, which is set when it is unsuccessfully defined; by default, it is, as mentioned above, "Western (Windows 1252)". There are two options for how to change the settings: either rewrite them in the standard settings, or add them to the custom ones. The latter is preferable, and the last paragraph explains why. Well, in fact, we will use the second option and proudly add the 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 like this:

You can find out the current file encoding in different ways, there are special plugins (for example, the Encoding Helper package), but I prefer the option to make it myself. An example of writing such a simple plug-in can be viewed in another article (under construction, the link will be here).

Hotkeys

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

("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 operations carried out in the editor. As an example, let's add hotkeys to convert the case of text 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 custom, key settings are no exception. Therefore, we call "Key Bindings - User" and write the settings there. The command is known, the question remains 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 in use - the combinations from the user set will overwrite the default ones. After 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 a file, select a word or put the cursor in it, press our favorite key combination "ctrl + alt + shift + t" and see that our work was not very in vain.

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

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

Color scheme

Many are faced with an inconvenient for them color scheme, it changes even easier.

The most classic scheme is "iPlastic". All schemas are separate files, have the * .tmTheme extension, and are an XML file. So you can edit, download, insert, share, etc. They are located (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 located at this address.

Creating a simple plugin

Let's set the goal to display the current file encoding in a pop-up window using a keyboard shortcut Shift + F1... First you need to run the command Tools - New Plugin and in the file that appears, insert:

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

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

It remains to set a hotkey to the method: Preferences - Key Bindings - User... Add an element to the given 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'll show you how to turn ST into the perfect tool for this job.

Why not use any other text editor? The answer is simple - why produce entities? Sublime Text is packed full of useful features that iA Writer and other fancy Markdown editors (not to mention the monstrous Word) lack. From the obvious: code coloring, autocompletion, document “mini-map”, header 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 desired edit. Any operation can be performed without removing your hands from the keyboard, and it is also easy to connect a lot of external instruments you need. And there are so many customization possibilities that you can deal with different plugins all day long.

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 short 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 batch manager ... isn't it 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 self-explanatory 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 to activate the installation. Restart Sublime Text, click ( on OS X) to open a command line (it's not the same as a console!), type install and press Enter. Before us is a directory with plugins. Now it is enough to type the name of the desired one and press Enter again. It will download and install automatically. In most cases, you will need to restart the program further. The Package Control item will also appear in the Sublime menu, which opens access to other important features: first of all, updating and uninstalling packages is important.

Markdown


We told you about Markdown back in September 2012 (article "Meet. This is Markdown"). This is the best of the invented formats for working with text - 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 spellchecker 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 has saved a lot of time for both authors and designers.

For the syntax, visit the website of the language's creator, John Gruber. Another interesting tool is the optional CriticMarkup markup tool, which allows you to add comments and corrections to your 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 writing tool But the plugin not only adds code highlighting, but also changes the appearance of the editor. A light theme, reminiscent of typescript pages, appears, and line numbers and command completion are 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 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 header, in the same way that Sublime can collapse code. However, this mode of operation will conflict with MarkdownEditing. But there is another useful function - the 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 spelling, but it's easy to fix: just download the dictionaries borrowed from OpenOffice and perform 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 a system spell checker. Not to say that OS X's built-in validation is good, but it gets better with each version of the system, and it certainly does not yield 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 drawback is that the list of replacement options is not shown in the right-click context menu. Instead, you can place the cursor on the misspelled word and press .

Word counter

Those who work with text professionally and are paid for the number of characters or words (like, for example, the authors of "Hacker"), 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 plug-in that sets the counter to the Sublime Text status bar has the uncomplicated name WordCount. With the default settings, the word count will be displayed all the time, and there will also be an interesting opportunity to see the number of characters in the 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)

Highlighting words

Tautology is one of the main problems facing the authors of the texts. Sometimes memory fails us and we forget that we have just used a word. You can drill through paragraphs with a glance, trying to determine if it has occurred recently, or you can put the WordHighlight plugin and, by clicking on the words, see them highlighted throughout the document. Aha! In the previous sentence there are two words “you can”! It's okay, this is the author's idea.

Clickable links

It's a good idea to add another plugin for Markdown syntax highlighting - ClickableURLs. As the name suggests, it should make the hyperlinks found in the document clickable. Unfortunately, not everything is so simple: apparently, the Sublime Text APIs do not allow plugins to do 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 positioned on them and a certain key combination is pressed. On Windows and Linux it is , on OS X - .

Autodetect encoding

Encoding Helper plugin is designed to automatically detect file encoding. 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 wrong. In such cases, the Encoding Helper guesses the required encoding and displays a message in the status line telling which encoding is used and which, most likely, should be. Conversion is not performed automatically, but an item will appear in the Edit menu that allows you to translate the document into Unicode from the encoding that Helper defined. If he determined incorrectly, you can independently select the desired encoding from his menu.

Clipboard history

Often, when copying text, the thought revolves in my head whether there is already something valuable in the clipboard that must first be pasted somewhere before using the clipboard again. Many specialized utilities that work not only with Sublime can save this burden. However, such a plugin also exists - it is called Clipboard History. It works very simply: press the combination (or wild in OS X) and we see all the previous entries that fell into the clipboard. Select any and paste it into the text. To not open the menu, you can press ( on Macs) and immediately insert the entry preceding the current one.

To-do lists


Productivity experts say that 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 equip it with the PlainTasks plugin. After installing it and restarting Sublime, the first thing to do is open the PlainTasks help. It explains in detail how to create new cases ( or depending on the system), mark them complete or canceled, tag them, and so on. The main drawback of this plugin is that you cannot 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 for opening links. An 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.