Skip to content

Instantly share code, notes, and snippets.

@tweekmonster
Created January 26, 2018 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tweekmonster/0e9dc69b36c8787f93f95489e202c326 to your computer and use it in GitHub Desktop.
Save tweekmonster/0e9dc69b36c8787f93f95489e202c326 to your computer and use it in GitHub Desktop.
Show relative number column when using certain operator keys
" Requires 'timeoutlen' to be low enough for this to be practical:
" set timeoutlen=100
function! s:relative_number_op(key) abort
let old_rn = &l:relativenumber
let &l:relativenumber = 1
redraw
let seq = a:key
while 1
echo seq
let next_key = nr2char(getchar())
if next_key ==# "\<esc>"
let seq = next_key
break
endif
let seq .= next_key
if next_key !~# '\d\+'
break
endif
endwhile
let &l:relativenumber = old_rn
redraw
return seq
endfunction
function! s:op_hook(key) abort
execute 'nnoremap <silent><expr> ' . a:key . ' <sid>relative_number_op("' . a:key . '")'
endfunction
call s:op_hook('c')
call s:op_hook('d')
call s:op_hook('y')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment