visualrepeat.vim 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. " visualrepeat.vim: Repeat command extended to visual mode.
  2. "
  3. " DEPENDENCIES:
  4. " - visualrepeat.vim autoload script
  5. "
  6. " Copyright: (C) 2011-2013 Ingo Karkat
  7. " The VIM LICENSE applies to this script; see ':help copyright'.
  8. "
  9. " Maintainer: Ingo Karkat <ingo@karkat.de>
  10. "
  11. " REVISION DATE REMARKS
  12. " 1.10.003 04-Sep-2013 ENH: Use the current cursor virtual column when
  13. " repeating in linewise visual mode. This allows
  14. " repeats of e.g. "t." that make more sense from
  15. " the current cursor position than from the start
  16. " of the line, and it doesn't interfere with the
  17. " normal linewise repeat, because in that mode,
  18. " the cursor is on the first column by default.
  19. " Abort further commands on error by using echoerr
  20. " inside the mapping (using a copy of the
  21. " implementation of ingo#err#Get()).
  22. " 1.00.002 13-Dec-2011 Prepared for publish.
  23. " 001 18-Mar-2011 file creation from ingomappings.vim.
  24. " Avoid installing twice or when in unsupported Vim version.
  25. if exists('g:loaded_visualrepeat') || (v:version < 700)
  26. finish
  27. endif
  28. let g:loaded_visualrepeat = 1
  29. let s:save_cpo = &cpo
  30. set cpo&vim
  31. " In linewise visual mode, after entering the command line with :, the current
  32. " cursor position is lost. Therefore, capture the cursor's virtual column via a
  33. " no-op expression mapping.
  34. xnoremap <expr> <SID>(CaptureVirtCol) visualrepeat#CaptureVirtCol()
  35. xnoremap <script> <silent> . <SID>(CaptureVirtCol):<C-u>
  36. \if ! visualrepeat#repeat()<Bar>
  37. \ echoerr visualrepeat#ErrorMsg()<Bar>
  38. \ if &cmdheight == 1<Bar>
  39. \ sleep 500m<Bar>
  40. \ endif<Bar>
  41. \ execute 'normal! gv'<Bar>
  42. \endif<CR>
  43. " In visual mode, the mode message will override the error message. Therefore,
  44. " sleep() for a short while to allow the user to notice it.
  45. let &cpo = s:save_cpo
  46. unlet s:save_cpo
  47. " vim: set ts=8 sts=4 sw=4 noexpandtab ff=unix fdm=syntax :