Home VIM Simplifying Work with Russian Texts in Sublime Text 3 + Vintage

Simplifying Work with Russian Texts in Sublime Text 3 + Vintage

by admin

If you started recently: 1) to use Sublime Text and/or 2) to use Vintage plugin and/or 3) to edit a lot of Russian (or vice versa English) text using ST3+Vintage you probably already felt what pain you feel about commands assigned to punctuation characters – "$", "", ", """ etc. In a little note under the cat, I want to offer you a couple of crutches that help alleviate this pain to a great extent.

You may not have known that a big part of the Vintage plugin is a bunch of bindings of standard Vim commands to their implementation in the plugin, such as :

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

So, the above problem is rooted in the fact that this bindin does not know whether the key was pressed 4/$/; (and you must perform "end of line") or ;/r/: (and one must perform "repeat character search"). That is, in fact, the bindings do not know the current layout. If the plugin could tell the current layout, everything would be fine.

And it turns out that it is possible to make this hint – bindings have a "context" that can look in setings :

{"key": "setting.is_rus"}

With this trick, we can change the behavior of ";" to "end of line" only if the setting "is_rus" 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 perfect – if you edit a file where there are roughly equal amounts of text in Russian and English, then one of the languages will suffer anyway. Moreover, if you switch between the files in different languages at least once every half an hour, it’s not very convenient to look through the settings every time.

Of course, I’d like to show you a couple more lines that would automatically look at the system layout and put the value "is_rus". But right now I don’t know how to do it – maybe later I’ll figure it out and I’ll share the results.

Still, I have a second crutch for you that allows you to alleviate this pain to a large extent. It’s based on the "toggle_setting" command, which lets you toggle a given boolean setting, and which we’ll hang on F8:

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

As a result, we are offered roughly the following way of working: we write the code, stumble on one of the commands, swear, press F8, work quietly. In half an hour we start writing an article on the Hubr, stumble on one of the commands, swear, press F8, finish the article quietly.

As a base I will share with you the bindings that I managed to stumble on after discovering this crutch set :

{ "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 anyone can suggest a better solution to this problem, please tell me in the comments.

P.S. Ready config with bindings for russian characters

You may also like