vim-textobj-user icon indicating copy to clipboard operation
vim-textobj-user copied to clipboard

Underscore in pattern is not recognized

Open ku1ik opened this issue 13 years ago • 8 comments

Hi,

I don't know if I'm doing sth wrong but following code doesn't work for me:

call textobj#user#plugin('handyobjects', {
  'underscores': {
    'select-i': 'iu',
    'select-a': 'au',
    '*pattern*': ["_", "_"]
  }
}

What I want to achieve is to select "in" and "a" text between underscore characters - "_". But after typing "ciu" when the cursor is between underscores doesn't work, vim just enters insert mode.

Should I use something else for pattern regexps?

Regards, Marcin

ku1ik avatar Oct 21 '10 19:10 ku1ik

Thank you for the feedback. I'll investigate the problem. Please wait a moment.

kana avatar Oct 22 '10 10:10 kana

textobj-user doesn't consider about using the same pattern to express the beginning and the end of a range. I'll fix it later.

As a workaround, use the following configuration instead. It emulates the original configuration you wrote, though it may not work as you expect in a specific situation.

call textobj#user#plugin('handyobjects', {
\   'underscores_a': {
\     'select': 'au',
\     '*pattern*': '_[^_]*_'
\   },
\   'underscores_i': {
\     'select': 'iu',
\     '*pattern*': '_\zs[^_]\+\ze_'
\   },
\ })

kana avatar Oct 22 '10 11:10 kana

Great, thanks for help. I'll watch this repository for updates ;)

Btw, I also tried to change text between pipes "|" using "ci|" but pipe character isn't allowed unfortunately. But I suspect this won't be easy to workaround, am I right?

Anyway, awesome plugin, good work man.

LunarLogic avatar Oct 22 '10 12:10 LunarLogic

Oops, previous comment was mine, but I forgot that I'm using different GH account :)

ku1ik avatar Oct 22 '10 12:10 ku1ik

Btw, I also tried to change text between pipes "|" using "ci|" but pipe character isn't allowed unfortunately. But I suspect this won't be easy to workaround, am I right?

It's not hard as you imagined. Use the following:

call textobj#user#plugin('handyobjects', {
\   'pipes_a': {
\     'select': 'a<Bar>',
\     '*pattern*': '|[^_]*|'
\   },
\   'pipes_i': {
\     'select': 'i<Bar>',
\     '*pattern*': '|\zs[^_]\+\ze|'
\   },
\ })

I suspect that you wrote a|/i| for select. It doesn't work. You have to wrote a<Bar>/i<Bar> instead.

Because |, the pipe character is used to separate multiple commands in a line. Essentially, textobj-user just executes a bunch of :map commands. For example, if a| is given for select, textobj-user will execute :map commands like the following:

vnoremap a|  (((magical stuff to select a specific text)))
onoremap a|  (((magical stuff to select a specific text)))
...

But Vim interprets the above commands as follows:

vnoremap a
(((magical stuff to select a specific text)))
onoremap a
(((magical stuff to select a specific text)))
...

So it doesn't work.

kana avatar Oct 22 '10 13:10 kana

Thanks! You made my day ;)

ku1ik avatar Oct 22 '10 14:10 ku1ik

I had the same problem making a regex matcher. I am completely astounded no one has made a vim-textobj-regex yet. I was able to get it working with this:

call textobj#user#plugin('regex', {
\   'regex_a': {
\     'select': 'a/',
\     '*pattern*': '\/.*\/[gicm]\{0,}'
\   },
\   'regex_i': {
\     'select': 'i/',
\     '*pattern*': '\/\zs.\+\ze\/'
\   },
\ })

I don't know if it's worthy to make a repo just for that, but maybe it is just so people can find it.

AndrewRayCode avatar May 18 '12 19:05 AndrewRayCode

@DelvarWorld make it a repo!

throughnothing avatar May 19 '12 04:05 throughnothing