vim同一按键不同命令
function! Jump(jumpcommands)
let l:location = getcurpos('.')
for jumpkey in a:jumpcommands
execute "normal! " jumpkey
if l:location != getcurpos('.')
break
endif
endfor
endfunction
function! Jumptails()
call Jump(['$', 'L$', 'G'])
endfunction
function! Jumpheads()
call Jump(['0', 'H', 'gg'])
endfunction
inoremap <silent> <End> <Esc> :call Jumptails()<CR> i
nnoremap <silent> <End> :call Jumptails()<CR>
inoremap <silent> <Pos1> <Esc> :call Jumpheads()<CR> i
nnoremap <silent> <Pos1> :call Jumpheads()<CR>
不跟踪最后命令而只检查光标位置.
它通过存储当前列来"检查"当前位置,然后只执行所需移动之一,比较新列是否等于之前列,如果是,则执行下一个移动,等等.
该Jumpheads()功能使用<Pos1>键在相反方向(向上)执行相同操作.如果vim中存在这样的命令,还可添加类似跳转到段落或函数的结尾/开头.
副作用是,如果在两者之间做其他事情,就会打破循环.此外,它非常简单;)
浙公网安备 33010602011771号