2

Given that I have string AABBAABBAA. I cannot find two AABBAA with the / that vim provides. Is there any option to enable this behaviour or I need a script/plugin?

1 Answer 1

4

This is possible if you unset flag c in setting 'cpoptions' (alias 'cpo'). Absence of that flag is described thusly:

When not present searching continues one character from the cursor position. With 'c' "abababababab" only gets three matches when repeating "/abab", without 'c' there are five matches.

Now the simple pattern...

AABBAA

...will match both occurrences in the double quotes.

A more comprehensive illustration...

" Save current value
:let oldcpo=&cpo
" Unset 'c'
:set cpo-=c
" Search as needed
/AABBAA
n
...
" Restore previous value
:let &cpo=oldcpo

(This makes no assumptions about whether c is set to begin with, thus the save/restore of oldcpo as well as the unsetting of c.)

1
  • 2
    This solves my question, thank you! And I just find the neovim way to remove this option with vim.opt.cpo:remove({'c'}).
    – job_start
    Dec 18, 2021 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.