Skip to content

Instantly share code, notes, and snippets.

@flavius
Forked from dahu/gist:5160260
Created March 16, 2013 12:07
Show Gist options
  • Save flavius/5176120 to your computer and use it in GitHub Desktop.
Save flavius/5176120 to your computer and use it in GitHub Desktop.
" HJKL repetition trap
" Barry Arthur, 2013-03-14
" depends on your :help 'updatetime setting
let g:cursor_moving = 0
function! TrapMovementKeys(key)
augroup CursorMoving
au!
autocmd CursorMoved * let g:cursor_moving = 1
augroup END
if ! g:cursor_moving
return a:key
else
return ''
endif
endfunction
nnoremap <expr> h TrapMovementKeys('h')
nnoremap <expr> j TrapMovementKeys('j')
nnoremap <expr> k TrapMovementKeys('k')
nnoremap <expr> l TrapMovementKeys('l')
augroup CursorMovingOff
au!
autocmd CursorHold * let g:cursor_moving = 0
augroup END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment