Skip to content

Instantly share code, notes, and snippets.

@dahu
Created March 14, 2013 10:18
Show Gist options
  • Save dahu/5160260 to your computer and use it in GitHub Desktop.
Save dahu/5160260 to your computer and use it in GitHub Desktop.
HJKL repetition trap for Vim
" 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