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