Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug while changing inside angle-braces #40

Closed
kshenoy opened this issue Mar 14, 2014 · 3 comments
Closed

Bug while changing inside angle-braces #40

kshenoy opened this issue Mar 14, 2014 · 3 comments

Comments

@kshenoy
Copy link

kshenoy commented Mar 14, 2014

This is my code

nnoremap <A-f> [I:let nr = input("Find: ")<Bar>exe "normal " . nr ."[\<C-I>"<CR>

My cursor is on the dash in <C-I>. If I type di<, the line changes to

nnoremap <A-f> [I:let nr = input("Find: ")<Bar>exe "normal " . nr ."[\<C-I>"<>

instead of

nnoremap <A-f> [I:let nr = input("Find: ")<Bar>exe "normal " . nr ."[\<>"<CR>

as expected.

@wellle
Copy link
Owner

wellle commented Mar 15, 2014

Thank you for your report. I can reproduce it and found that the reason for this lies in Vim itself.

To confirm, try this. Start Vim without settings and plugins:

vim -u NONE --noplugins

Enter the text \<x>, place your cursor on x and type di>. Vim doesn't delete the x. Try the same without the backslash <x> and it works. I am using these stock text objects in targets.vim, so this behavior gets forwarded to you.


Here are some internals I found in case you are interested:

The command di> triggers a call stack including the following calls:

1. nv_object
2. current_block
3. findmatch
4. findmatchlimit

The findmatchlimit call searches for the opening < left to the cursor. It also recognizes that there is a backslash in front of the bracket \< and basically rejects it. The cpoptions flag M can normally be used to ignore these backslashes and I would have advised you to try this setting. Unfortunately the calling function current_block overwrote cpoptions="%" before calling findmatch to make findmatchlimit ignore certain brackets in quoted strings. This is all reasonable, but it also means that adding M to your cpoptions couldn't help here.


In summary the behavior your observed is the result of Vim's very internals. I would guess that a lot of thought went into these details over the years, so I'm not sure we want to fiddle with it.

The idea behind all this is documented in :help cpo-M and :help cpo-%.

If you're still not convinced I would recommend to address this on vim_dev and propose to set cpoptions to %M or % depending on whether or not M was part of the original cpoptions string. That way you could :set cpo+=M locally and everything should work for you. But I don't know about other implications that change in Vim's core would have for everybody else.

@kshenoy
Copy link
Author

kshenoy commented Mar 18, 2014

Thanks for the digging into it. You're correct; my apologies for not trying it out on a stock setup.

@kshenoy kshenoy closed this as completed Mar 18, 2014
@wellle
Copy link
Owner

wellle commented Mar 18, 2014

No worries. I learned some new Vim internals :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants