In the script below, where # and n are remapped, n goes the wrong direction after #. To see: vim -u NONE bad.bim :so % gg/ba<cr>nnn#n -- the last n goes forward. we expect it to move backward.
But when script is rewritten to the form #2, then n after # works correcty. Plain moving the 'silent! exe "norm!"...' out of the function changes the behavior. Yakov ---------- bad.vim ---------------------------- " ba ba ba ba ba ba ba ba :set nocp nnoremap # :call Foo('#')<cr> nnoremap n :call Foo('n')<cr> func! Foo(cmd) silent! exe "norm! " . a:cmd endfun " test sequence: gg/ba<cr>nnn#n " expected: last 'n' to go backwards " actual : last 'n' to go forward -------------------------------------------------------------------------------- Form 2 that works ok --------------------- ok.vim ----------------------- " ba ba ba ba ba ba ba ba :set nocp nnoremap # :silent! exe "norm! #"<cr> nnoremap n :silent! exe "norm! n"<cr> " test sequence: gg/ba<cr>nnn#n " expected: last 'n' to go backwards " actual : ok --------------------------------------------------------------------------------