1

I want to create a custom search in vimscript, using this line for searching:

:execute "normal gg/[A-Z]\\+*.:\<cr>"

it will tell me (correctly) that it searched for the pattern:

/[A-Z]\+3a.*:

but it will not highlight/search for anything. Pressing 'n' will continue the last search from before. Executing the exact same command directly in vim has the desired effect.

Can somebody explain to me why this doesn't work and how to do it correctly?

  • As i stated inthe question, the command works fine if executed normally and not withing a script meaning i have set hlsearch. – Sheppy Oct 30 '16 at 15:19
  • See :h function-search-undo – VanLaser Oct 30 '16 at 15:25
  • :execute is useless, here: you only need :normal .... – romainl Oct 30 '16 at 16:13
1

The reason why this is not working is stated in :h function-search-undo. I worked around this by letting my function return the line and mapping it like this:

map <KEY> :execute function()<CR>

Credits to VanLaser.

  • 1
    It's :call Myfunction()<CR>. – romainl Oct 30 '16 at 16:12

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.