Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
%
mapping seems broken in visual mode.To reproduce, run this shell command:
/path/to/matchit/
needs to be set to the actual path of the plugin.Expected behavior: The block containing the lines
ccc
andddd
is selected.Actual behavior: The block containing the lines
ccc
andddd
is not selected.This is broken because that's not how the builtin
%
command behaves without the matchit plugin.The issue disappears if we start the selection from after the end of the block:
A similar issue exists when we start the selection while the cursor is right on a brace (not on a line above):
Notice that this time, the first
%
has correctly worked: the block is selected. But the second%
has failed: the block should have been de-selected.And again, the issue disappears when we start the selection from the end of the block rather than from its start.
I don't know what the right fix is yet. But I have noticed that using the pseudo-key
<Cmd>
fixed the issue. Using<Cmd>
is better anyway, because it has fewer side-effects: it doesn't trigger theCmdline*
events. Also, it makes the code less verbose: no need of<silent>
nor<C-U>
.This bug has always annoyed me, and is one of the reasons why I've used
vim-matchup
up until now. But I'm trying to move away from big/complex plugins as they are too time-consuming to debug.matchit
is much shorter/simpler (hopefully it will stay that way), so I would like this bug to be fixed to use it again.Note that even though we use
<Cmd>
, we still need<silent>
in 1 mapping.<Cmd>
only makes the command silent until the next<CR>
; not beyond:Also,
<C-\><C-N>
might be replaced with<Esc>
, but in a mapping, I try to avoid the latter, because it's too ambiguous. For example:This outputs:
While I would have expected:
The issue disappears if we replace
<Esc>
with<C-\><C-N>
:Bottom line:
<Esc>
is ambiguous because it can mean "start of a special keycode", or "escape to normal mode". In contrast,<C-\><C-N>
is not ambiguous; it can only mean "make sure I'm in normal mode" which is what we really want here.