Vim: bug: press % for matching does not work or goes to wrong locations

Created on 25 Aug 2016  路  10Comments  路  Source: VSCodeVim/Vim

Please _thumbs-up_ 馃憤 this issue if it personally affects you! You can do this by clicking on the emoji-face on the top right of this post. Issues with more thumbs-up will be prioritized.


What did you do?

Open this file https://github.com/telerik/kendo-ui-core/blob/master/src/kendo.color.js in visual studio code and switch to NORMAL MODE, go to last line which begins with "}, typeof define == 'function' && define.amd", move cursor to col 1, that's should be under '}', now press %.

What did you expect to happen?

The cursor should go to '{' in line 3.

What happened instead?

Nothing happens.
Many times, press % will cause the cursor go to wrong places.

Technical details:

  • VSCode Version: 1.3 /1.4
  • VsCodeVim Version: _[please ensure you are on the latest]_ 0.1.7
  • OS: win7, 64bit
kinbug sizM

Most helpful comment

The use of editor.action.moveCarretLeftAction and editor.action.moveCarretRightAction was the trick I needed to get % to work properly. I had found editor.action.jumpToBracket and bound it to % in normal mode, but it would only pretend to move the cursor to the matching bracket; any kind of interaction in normal mode would "jump" back to the previous cursor location.

Thank you, @bijoutrouvaille! My prefs JSON snippet looks like this:

    "vim.normalModeKeyBindingsNonRecursive": [
        {
            "before": [
                "%"
            ],
            "commands": [
                "editor.action.jumpToBracket",
                "editor.action.moveCarretLeftAction",
                "editor.action.moveCarretRightAction"
            ]
        }
    ]

All 10 comments

Yeah, this is a known issue unfortunately, We don't correctly handle cases like ( ")" ). Feel free to add it if you want 馃槈

@johnfn This seems to be fixed?

Indeed, this looks to be working on 0.2.0.

That's super weird, because our matching algorithm has never changed!

https://github.com/VSCodeVim/Vim/blob/master/src/matching/matcher.ts#L21

Something like ( ")" ) continues to trip us up, so I'm gonna keep this one open for now. 馃槈

Is there any reason we don't just useeditor.action.jumpToBracket?

Oh, here's one... It doesn't support multiple cursors >:(

Ah multi cursors, the cause of, and solution to, all of VSCodeVim's problems.

Also affects motions like [{ and ]}. Would guess the same code is involved in finding pairs here?

I don't use multiple cursors, so I made this mapping in "vim.otherModesKeyBindings" and it has worked so far:

{
      "before": ["%"],
      "commands": [
        {
          "command": "editor.action.jumpToBracket",
          "args": []
        },
        {
          "command": "editor.action.moveCarretLeftAction",
          "args": []
        },
        {
          "command": "editor.action.moveCarretRightAction",
          "args": []
        }
      ]
    }

The left-right carret motion at the end makes the window scroll to the new carret position.

The use of editor.action.moveCarretLeftAction and editor.action.moveCarretRightAction was the trick I needed to get % to work properly. I had found editor.action.jumpToBracket and bound it to % in normal mode, but it would only pretend to move the cursor to the matching bracket; any kind of interaction in normal mode would "jump" back to the previous cursor location.

Thank you, @bijoutrouvaille! My prefs JSON snippet looks like this:

    "vim.normalModeKeyBindingsNonRecursive": [
        {
            "before": [
                "%"
            ],
            "commands": [
                "editor.action.jumpToBracket",
                "editor.action.moveCarretLeftAction",
                "editor.action.moveCarretRightAction"
            ]
        }
    ]
Was this page helpful?
0 / 5 - 0 ratings

Related issues

edwintorok picture edwintorok  路  3Comments

elithrar picture elithrar  路  3Comments

triztian picture triztian  路  3Comments

waltiam picture waltiam  路  3Comments

rajinder-yadav picture rajinder-yadav  路  3Comments