vim-textobj-user
vim-textobj-user copied to clipboard
Underscore in pattern is not recognized
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
Thank you for the feedback. I'll investigate the problem. Please wait a moment.
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_'
\ },
\ })
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.
Oops, previous comment was mine, but I forgot that I'm using different GH account :)
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.
Thanks! You made my day ;)
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.
@DelvarWorld make it a repo!