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

Underscore in pattern is not recognized #2

Open
ku1ik opened this issue Oct 21, 2010 · 8 comments
Open

Underscore in pattern is not recognized #2

ku1ik opened this issue Oct 21, 2010 · 8 comments
Labels

Comments

@ku1ik
Copy link

ku1ik commented Oct 21, 2010

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

@kana
Copy link
Owner

kana commented Oct 22, 2010

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

@kana
Copy link
Owner

kana commented Oct 22, 2010

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_'
\   },
\ })

@LunarLogic
Copy link

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.

@ku1ik
Copy link
Author

ku1ik commented Oct 22, 2010

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

@kana
Copy link
Owner

kana commented Oct 22, 2010

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.

@ku1ik
Copy link
Author

ku1ik commented Oct 22, 2010

Thanks! You made my day ;)

@AndrewRayCode
Copy link

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.

@throughnothing
Copy link

@delvarworld make it a repo!

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

No branches or pull requests

4 participants