Simplify working with Russian texts in Sublime Text 3 + Vintage

    If you 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 English) using ST3 + Vintage, then you probably already felt what kind of pain is associated with the commands assigned to punctuation characters - "$", ";", ".", ",", "" ", etc. In a short note under the cut, I want to offer you a couple of crutches that help to relieve this pain to a great extent.


    Perhaps you did not know that a significant part of the Vintage plugin is a bunch of binders 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, the problem indicated above has its roots in the fact that this binding does not know if the 4 / $ / key has been pressed; (and it is necessary to execute "at the end of the line") or; / f /: (and it is necessary to perform "repeat the search for the character"). That is, in fact, the binding does not know the current layout. If the plugin could tell the current layout, then everything would be great.


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


    {"key": "setting.is_rus"}

    With this trick we can change the behavior of the symbol ";" to "end of 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 are editing a file where there is an approximately equal amount of text in Russian and English, then one of the languages ​​will suffer anyway. Moreover, if you switch at least once every half an hour between files in different languages, then each time to climb into the settings is also not very convenient.


    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 this - maybe later I will figure it out and will definitely share the results.


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


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

    As a result, approximately the following method of work is proposed: we write the code, stumble on one of the teams, mate, press F8, work quietly. After half an hour, we begin to write an article on Habr, stumble on one of the teams, mate, press F8, add the article calmly.


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


      { "keys": ["\"", ""], "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 more successful solution to this problem - please tell us in the comments.


    PS Ready config with bindings of Russian characters


    Also popular now: