One option is for you to only really initiate the /\v
once you've actually started to search for something. You can do that by using a function that uses that uses getchar()
to read one character and then feedkeys()
to actually push the /\v
plus the read character into the search command-line.
Something like the following should work:
function! SearchBox()
" Replace the prompt:
echon '/'
" Get an initial search character.
let c = nr2char(getchar())
" TODO: Check whether it's a special character, whether
" we would like to handle it differently. For example:
if c ==# "\<CR>"
" Repeat last search.
call feedkeys('/'.c, 'n')
return
elseif c ==# "\<Esc>" || c ==# "\<C-c>"
" Cancel search.
call feedkeys("/\<C-c>", 'n')
return
endif
" When we're happy, actually start a search:
call feedkeys('/\v'.c, 'n')
endfunction
nnoremap <silent> / :call SearchBox()<CR>
You might need better handling of corner cases. I also didn't cover searching backwards with ?
. You might want to cover using /
from Visual mode or operator-pending mode.
But you get the idea. Something like this should address adding \v
by default to searches, while not doing so too early, and also possibly helping with some of the corner cases that using the nnoremap / /\v
mapping doesn't cover, such as repeating the last search with /
.
\v
causes incremental search to match everywhere, if I recall correctlydisplaced cursor
vim --clean
, addsomething
to a buffer, put your cursor ons
, then/\v
-- your cursor is now ono