天天看点

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>