Yakov Lerner wrote: > 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 > --------------------------------------------------------------------------------
When calling a user function the search pattern is saved and restored. See ":help :endfunction" and go up a few lines. -- If evolution theories are correct, humans will soon grow a third hand for operating the mouse. /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ download, build and distribute -- http://www.A-A-P.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///