Matching « and »

18 views
Skip to first unread message

gevisz

unread,
Sep 6, 2020, 8:16:44 AM9/6/20
to vim...@googlegroups.com
What line(s) of code should I add to my vimrc so that ci« behave in
the same way with respect to « and », as ci( behaves with respect to (
and )?

Gabriele

unread,
Sep 8, 2020, 6:33:58 PM9/8/20
to vim...@googlegroups.com
It's not very easy but there are some plugins that ought to make it
possible, such as vim-textobj-user
(https://www.vim.org/scripts/script.php?script_id=2100) and CountJump
(https://www.vim.org/scripts/script.php?script_id=3130).

I made a quick attempt with CountJump and managed to make it somewhat
partially work:

I installed it by reading the .vmb.gz in Vim, doing :UseVimball, reading
ingo-library-1.042.vmb.gz from
https://www.vim.org/scripts/script.php?script_id=4433 and doing
:UseVimball again.

I then used
 :call CountJump#TextObject#MakeWithCountSearch('','z','ai','','«','»')
which apparently registered a new iz text object: after that "ciz"
changed a «» block such as
«
a
b
c
»

to
«
»

However, it didn't work with inline strings («abc») and it left the
borders of the block unaltered:
«12
a
b
c
34»
became
«12

34»
after "ciz".

And I didn't manage to make it work with "ci«" (by replacing the z with
a «), but of course I don't have a keyboard with that key, I typed it in
with "C-K <<", maybe it can be made to work with some kind of mapping.


Kind regards,

Gabriele



Gabriele

unread,
Sep 8, 2020, 6:46:17 PM9/8/20
to vim...@googlegroups.com
On 09/09/2020 0.26, Gabriele wrote:
>  :call CountJump#TextObject#MakeWithCountSearch('','z','ai','','«','»')

Ooops, I pasted the wrong command, and trying the correct one which is:
:call CountJump#TextObject#MakeWithCountSearch('','z','ai','v','«','»')

I realized that it works a lot better than I reported in the other mail,
it works correctly inline just as ci( does!!!

I think I made the previous test with 'V' in place of 'v'...

So, this does seems to work well, if you can forgo using '«' for the
textObjectKey (or if your keyboard has that key, or you figure out a
mapping or other way to make it work)


Kind regards

gevisz

unread,
Sep 9, 2020, 10:15:32 AM9/9/20
to vim...@googlegroups.com
ср, 9 сент. 2020 г. в 01:46, Gabriele <gb...@tiscali.it>:
Thank you. I will try it.

Eli the Bearded

unread,
Sep 9, 2020, 7:56:56 PM9/9/20
to vim...@googlegroups.com
Hmmm. "set matchpairs=(:),{:},[:],<:>,«:»" works fine for %, but it
appears that i(, i<, i{, a(, and the like are special movements, not
just keying off matchpairs.

Would it be possible to make the iX and aX family of motions use that
setting too? That's probably the more general fix.

Elijah

Christian Brabandt

unread,
Sep 10, 2020, 3:36:23 AM9/10/20
to vim...@googlegroups.com
There is a patch floating around, to easily define text objects
delimited by the same character. I believe the latest version is here:
https://github.com/vim/vim/pull/958

But that does not handle a begin/end separator character.

Best,
Christian
--
Hardware scheppert, wenn man dagegen tritt.
Reply all
Reply to author
Forward
0 new messages