作为替代hardmode,下面的代码片段将允许您使用h
,j
,k
,和l
正常的,但产生的蜂鸣声,提醒你,当他们在连续快速使用。
function! s:BeepOnRepeat(key)
let count1 = v:count1
if !exists('s:last_time')
let s:last_time = reltime()
let s:repeat_count = 1
else
" increment the repeat count if `h`, `j`, `k`, or `l` was pressed
" within the last second, otherwise reset it
let now = reltime()
if str2float(reltimestr(reltime(s:last_time, now))) < 1
let s:repeat_count += 1
else
let s:repeat_count = 1
endif
let s:last_time = now
" produce an audible beep if a sequence of `h`, `j`, `k`, and/or `l`,
" greater than three, was pressed (within the repeat count time limit)
if s:repeat_count > 3
let savebelloff = &belloff
let savevisualbell = &visualbell
let &belloff = ''
let &visualbell = 0
execute "normal! \<Esc>"
let &belloff = savebelloff
let &visualbell = savevisualbell
endif
endif
execute 'normal! ' . count1 . a:key
endfunction
nnoremap <silent> h :<C-u>call <SID>BeepOnRepeat('h')<CR>
nnoremap <silent> j :<C-u>call <SID>BeepOnRepeat('j')<CR>
nnoremap <silent> k :<C-u>call <SID>BeepOnRepeat('k')<CR>
nnoremap <silent> l :<C-u>call <SID>BeepOnRepeat('l')<CR>
有关限制hjkl
使用的另一种方法,请参见vim-molasses。