Skip to content

Instantly share code, notes, and snippets.

@tansongyang
Last active June 12, 2018 22:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tansongyang/573fd4fc6f4667120a26e002bb22e55d to your computer and use it in GitHub Desktop.
Save tansongyang/573fd4fc6f4667120a26e002bb22e55d to your computer and use it in GitHub Desktop.
A BracketHighlighter plugin that implements Vintage's vi_move_to_brackets.
import BracketHighlighter.bh_plugin as bh_plugin
import sublime
class ViMoveToBrackets(bh_plugin.BracketPluginCommand):
"""
Move to Bracket plugin for Vintage.
Based on [Select Bracket plugin](https://github.com/facelessuser/BracketHighlighter/blob/st3-2.23.3/bh_modules/bracketselect.py).
"""
def run(self, edit, name):
"""
Jump to matching bracket
"""
left, right = self.left.end, self.right.begin
sel = self.selection[0]
status = self.view.get_status('mode')
if status == 'VISUAL MODE':
if sel.b < right:
self.selection = [sublime.Region(sel.a, right)]
else:
self.selection = [sublime.Region(sel.a, left)]
elif status != 'VISUAL LINE MODE':
if sel.b < right:
self.selection = [sublime.Region(right, right)]
else:
self.selection = [sublime.Region(left - 1, left - 1)]
def plugin():
"""Make plugin available."""
return ViMoveToBrackets

BracketHighlighter vi_move_to_brackets

A BracketHighlighter plugin that implements Vintage's vi_move_to_brackets.

Why

Vintage's % command jumps between matching brackets. I wanted BH to drive this behavior because it can handle more bracket types. However, after some discussion with facelessuser, I learned that I would have to write a plugin to get the exact behavior I was looking for.

Usage

Make sure BracketHighlighter is installed.

  1. Save vimovetobrackets.py under User\bh_modules.

  2. Add the following to your key bindings:

    {
        "keys": ["%"],
        "command": "bh_key",
        "args": {
            "plugin": {
                "type": ["__all__"],
                "command": "User.bh_modules.vimovetobrackets"
            }
        },
        "context": [{"key": "setting.command_mode"}]
    }
  3. Edit or create User\bh_core.sublime-settings and add "block_cursor_mode": true.

Notes

Only tested on ST3:

  • ST ver.: 3126
  • Platform: windows
  • Arch: x64
  • Plugin ver.: 2.23.3
  • Install via PC: True
  • mdpopups ver.: 1.13.1
  • backrefs ver.: 1.0.post1
  • markdown ver.: 2.6.6
  • pygments ver.: 2.1a0
  • jinja2 ver.: 2.8

Other Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment