vim - Is it possible to always overwrite a specific built-in command with a particular mapped command? -


i have following mapping in .vimrc.

" scroll arbitrary function scrolltopercent(percent)     let movelines=winheight(0)*a:percent/100      if has("float") && type(movelines)==type(0.0)         let movelines=float2nr(movelines)     endif      let oldso=&so     execute ":set so=" . movelines     execute "normal! zt"     execute ":set so=" . oldso endfunction  nnoremap zz :call scrolltopercent(25)<cr> 

this mapping causes command zz move line under current cursor 25% of way down top of screen, instead of usual behavior of moving 50% of way down.

i have observed that, if type second z greater delay after first z, mapping ignored , default behavior of zz kicks in. in particular, line under cursor move 50% of way down instead of 25% of way down.

based on answer this question, set timeoutlen high value, not want because mess other mappings should not kicked off if small delay separates keys.

is possible make mapping zz override default zz, without changing global option affect other mappings?

you map single z no-op. if type zz cursor jump, if wait long nothing @ happen.

i.e. use pair of mappings:

nnoremap zz :call scrolltopercent(25)<cr> nnoremap z  <nop> 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -