matchit.vim 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. " matchit.vim: (global plugin) Extended "%" matching
  2. " Maintainer: Christian Brabandt
  3. " Version: 1.17
  4. " Last Change: 2019 Oct 24
  5. " Repository: https://github.com/chrisbra/matchit
  6. " Previous URL:http://www.vim.org/script.php?script_id=39
  7. " Previous Maintainer: Benji Fisher PhD <benji@member.AMS.org>
  8. " Documentation:
  9. " The documentation is in a separate file: ../doc/matchit.txt
  10. " Credits:
  11. " Vim editor by Bram Moolenaar (Thanks, Bram!)
  12. " Original script and design by Raul Segura Acevedo
  13. " Support for comments by Douglas Potts
  14. " Support for back references and other improvements by Benji Fisher
  15. " Support for many languages by Johannes Zellner
  16. " Suggestions for improvement, bug reports, and support for additional
  17. " languages by Jordi-Albert Batalla, Neil Bird, Servatius Brandt, Mark
  18. " Collett, Stephen Wall, Dany St-Amant, Yuheng Xie, and Johannes Zellner.
  19. " Debugging:
  20. " If you'd like to try the built-in debugging commands...
  21. " :MatchDebug to activate debugging for the current buffer
  22. " This saves the values of several key script variables as buffer-local
  23. " variables. See the MatchDebug() function, below, for details.
  24. " TODO: I should think about multi-line patterns for b:match_words.
  25. " This would require an option: how many lines to scan (default 1).
  26. " This would be useful for Python, maybe also for *ML.
  27. " TODO: Maybe I should add a menu so that people will actually use some of
  28. " the features that I have implemented.
  29. " TODO: Eliminate the MultiMatch function. Add yet another argument to
  30. " Match_wrapper() instead.
  31. " TODO: Allow :let b:match_words = '\(\(foo\)\(bar\)\):\3\2:end\1'
  32. " TODO: Make backrefs safer by using '\V' (very no-magic).
  33. " TODO: Add a level of indirection, so that custom % scripts can use my
  34. " work but extend it.
  35. " Allow user to prevent loading and prevent duplicate loading.
  36. if exists("g:loaded_matchit") || &cp
  37. finish
  38. endif
  39. let g:loaded_matchit = 1
  40. let s:save_cpo = &cpo
  41. set cpo&vim
  42. nnoremap <silent> <Plug>(MatchitNormalForward) :<C-U>call matchit#Match_wrapper('',1,'n')<CR>
  43. nnoremap <silent> <Plug>(MatchitNormalBackward) :<C-U>call matchit#Match_wrapper('',0,'n')<CR>
  44. xnoremap <silent> <Plug>(MatchitVisualForward) :<C-U>call matchit#Match_wrapper('',1,'v')<CR>m'gv``
  45. xnoremap <silent> <Plug>(MatchitVisualBackward) :<C-U>call matchit#Match_wrapper('',0,'v')<CR>m'gv``
  46. onoremap <silent> <Plug>(MatchitOperationForward) :<C-U>call matchit#Match_wrapper('',1,'o')<CR>
  47. onoremap <silent> <Plug>(MatchitOperationBackward) :<C-U>call matchit#Match_wrapper('',0,'o')<CR>
  48. nmap <silent> % <Plug>(MatchitNormalForward)
  49. nmap <silent> g% <Plug>(MatchitNormalBackward)
  50. xmap <silent> % <Plug>(MatchitVisualForward)
  51. xmap <silent> g% <Plug>(MatchitVisualBackward)
  52. omap <silent> % <Plug>(MatchitOperationForward)
  53. omap <silent> g% <Plug>(MatchitOperationBackward)
  54. " Analogues of [{ and ]} using matching patterns:
  55. nnoremap <silent> <Plug>(MatchitNormalMultiBackward) :<C-U>call matchit#MultiMatch("bW", "n")<CR>
  56. nnoremap <silent> <Plug>(MatchitNormalMultiForward) :<C-U>call matchit#MultiMatch("W", "n")<CR>
  57. xnoremap <silent> <Plug>(MatchitVisualMultiBackward) :<C-U>call matchit#MultiMatch("bW", "n")<CR>m'gv``
  58. xnoremap <silent> <Plug>(MatchitVisualMultiForward) :<C-U>call matchit#MultiMatch("W", "n")<CR>m'gv``
  59. onoremap <silent> <Plug>(MatchitOperationMultiBackward) :<C-U>call matchit#MultiMatch("bW", "o")<CR>
  60. onoremap <silent> <Plug>(MatchitOperationMultiForward) :<C-U>call matchit#MultiMatch("W", "o")<CR>
  61. nmap <silent> [% <Plug>(MatchitNormalMultiBackward)
  62. nmap <silent> ]% <Plug>(MatchitNormalMultiForward)
  63. xmap <silent> [% <Plug>(MatchitVisualMultiBackward)
  64. xmap <silent> ]% <Plug>(MatchitVisualMultiForward)
  65. omap <silent> [% <Plug>(MatchitOperationMultiBackward)
  66. omap <silent> ]% <Plug>(MatchitOperationMultiForward)
  67. " text object:
  68. xmap <silent> <Plug>(MatchitVisualTextObject) <Plug>(MatchitVisualMultiBackward)o<Plug>(MatchitVisualMultiForward)
  69. xmap a% <Plug>(MatchitVisualTextObject)
  70. " Call this function to turn on debugging information. Every time the main
  71. " script is run, buffer variables will be saved. These can be used directly
  72. " or viewed using the menu items below.
  73. if !exists(":MatchDebug")
  74. command! -nargs=0 MatchDebug call matchit#Match_debug()
  75. endif
  76. let &cpo = s:save_cpo
  77. unlet s:save_cpo
  78. " vim:sts=2:sw=2:et: