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
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
.)
-
2This solves my question, thank you! And I just find the neovim way to remove this option with
vim.opt.cpo:remove({'c'})
. Commented Dec 18, 2021 at 15:23