📜 ⬆️ ⬇️

Simplify working with Russian texts in Sublime Text 3 + Vintage

If you have recently started: 1) use Sublime Text and / or 2) use the Vintage plugin and / or 3) edit a lot of text in Russian (or vice versa) using ST3 + Vintage, then most likely you have already felt the pain associated with the teams assigned to punctuation characters - "$", ";", ".", ",", "" ", etc. In a small note under the cut, I want to offer you a couple of crutches that help this pain greatly alleviate.


Perhaps you did not know that a significant part of the Vintage plugin is a bundle of bindings of standard Vim commands for their implementation in the plugin, for example:


{ "keys": [";"], "command": "set_repeat_move_to_character_motion", "context": [{"key": "setting.command_mode"}] }, 

So, with the problem outlined above, the roots lie in the fact that this binding does not know whether the 4 / $ / key was pressed; (and it is necessary to perform "at the end of the line") or; / f /: (and it is necessary to perform "repeat the search for the character"). That is actually binding does not know the current layout. If the plugin could prompt the current layout, then everything would be great.


And it turns out that it is possible to make this hint - for this, the bindings have a "context", which can look into the settings:


 {"key": "setting.is_rus"} 

With this trick, we can change the behavior of the character ";" to "to the end of the line" only if the "is_rus" setting is set to true:


  { "keys": [";"], "command": "set_motion", "args": { "motion": "vi_move_to_hard_eol", "motion_args": {"repeat": 1, "extend": true}, "inclusive": true, "clip_to_line": true }, "context": [{"key": "setting.command_mode"},{"key": "setting.is_rus"}] } 

Unfortunately, this solution is not ideal - if you edit a file where there is approximately an equal amount of text in Russian and English, then one of the languages ​​will suffer in any case. Moreover, if you switch between files in different languages ​​at least once every half an hour, then every time you’ll not be comfortable in the settings.


Of course, I would like to show you a couple more lines that would automatically look at the system layout and put the value "is_rus". But now I do not know how to do it - maybe later I will deal with it and be sure to share the results.


But still, I have a second crutch for you, which allows you to greatly alleviate this pain. It is based on the "toggle_setting" command, which allows you to switch a given boolean setting, and which we will hang on F8:


  { "keys": ["f8"], "command": "toggle_setting", "args": {"setting": "is_rus"} } 

As a result, the following way of working is proposed: we write the code, we stumble on one of the teams, we swear, we press F8, we work quietly. After half an hour, we begin to write an article on Habr, we stumble on one of the teams, swear at, press F8, finish the article calmly.


As a base, I will share with you the bindings that I managed to stumble upon after opening this set of crutches:


  { "keys": ["\"", "<character>"], "command": "vi_replay_macro", "context": [{"key": "setting.command_mode"},{"key": "setting.is_rus"}] }, { "keys": [";"], "command": "set_motion", "args": { "motion": "vi_move_to_hard_eol", "motion_args": {"repeat": 1, "extend": true}, "inclusive": true, "clip_to_line": true }, "context": [{"key": "setting.command_mode"},{"key": "setting.is_rus"}] }, { "keys": ["."], "command": "show_panel", "args": { "panel": "incremental_find", "select_text": false, "reverse": false }, "context": [{"key": "setting.command_mode"},{"key": "setting.is_rus"}] } 

If someone can offer a better solution to this problem - please tell us in the comments.


PS Ready config with Russian characters bindings


')

Source: https://habr.com/ru/post/321776/


All Articles