This is actually a know issue (see issues #2 and #15 in the plugin bug tracker).
The author of the plugin suggested a workaround of the following form:
call textobj#user#plugin('handyobjects', {
\ 'underscores_a': {
\ 'select': 'ar',
\ '*pattern*': '%[^%]*%'
\ },
\ 'underscores_i': {
\ 'select': 'ir',
\ '*pattern*': '%\zs[^%]\+\ze%'
\ },
\ })
The idea is not to use a beginning and a ending pattern but just one regex to match the region:
For the ar
motion the regex %[^%]*%
defines a region starting with a %
followed by anything which is not %
repeated zero or more times (i.e. [^$]*
) followed by another %
.
For the ir
motion the regex is more or less the same but the match excludes the delimitating %
characters thanks to \zs
and \ze
.
So it is possible to use the same pattern for begin and end but you need to use only one regex.
Important note This is a workaround and it has a major drawback: I wasn't able to use it to match a region on several lines (which can be a problem in some cases).
Edit In some cases it is possible to create text objects which matches the same pattern on different lines. Here is what the author suggested to match two _
on different lines:
call textobj#user#plugin('handyobjects', {
\ 'underscores_a': {
\ 'select': 'au',
\ 'pattern': '_\_[^_]*_'
\ },
\ 'underscores_i': {
\ 'select': 'iu',
\ 'pattern': '_\zs\_[^_]\+\ze_'
\ },
\ })
Note That after a really quick test I wasn't able to make it work with %
characters but I guess it what because of some escaping problem or something like this. I think that with some work on the regex it is possible to do it.
%
-delimited regions? You could use something like this, perhaps: github.com/kana/vim-textobj-syntax