Skip to content

Instantly share code, notes, and snippets.

@teranex
Created January 20, 2013 14:23
Show Gist options
  • Save teranex/4579025 to your computer and use it in GitHub Desktop.
Save teranex/4579025 to your computer and use it in GitHub Desktop.
This is a vim plugin I started writing to 'unlearn' repeatedly hitting the j and k keys to move vertically across the screen. I didn't finish it however, so I'm just making it public here, should it be useful for anybody...
let g:punisher_keys = ['j', 'k', 'h', 'l', 'dd', 'x', 'X']
let g:punisher_max_repeats = 4
let g:punisher_mode = 'normal' " normal, hard, extreme, low
" TODO:
" - dot-command fixen
" - config options
" - arrows etc
" - arrows in insert mode
" - hard en extreme mode
" - name!!!
let s:counter = 0
let s:last_key = ''
function RepeatPunisherReset()
let s:counter = 1
let s:last_key = ''
endfunction
function RepeatPunisherDoPunish(key, count)
echo "You already used the '".a:key."'-command ".a:count." times!"
if g:punisher_mode == 'low'
exec "normal! ".a:key
endif
endfunction
function RepeatPunisher(key) range
if v:count1 == 1 && s:last_key == a:key
let s:counter = s:counter + 1
if s:counter > g:punisher_max_repeats
call RepeatPunisherDoPunish(a:key, s:counter)
else
exec "normal! ".a:key
endif
else
call RepeatPunisherReset()
let cmd = "normal! ".v:count1.a:key
exec cmd
endif
let s:last_key = a:key
endfunction
function s:SetupKeys()
for key in g:punisher_keys
exec "nnoremap ".key." :<C-U>call RepeatPunisher('".key."')<CR>"
endfor
endfunction
augroup RepeatPunisher
autocmd CursorHold * call RepeatPunisherReset()
augroup END
call s:SetupKeys()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment