aboutsummaryrefslogtreecommitdiff
path: root/plugin/nextag.vim
blob: 68bb0fcd3b442b2ffdef8aa747c3f0179217bbe3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"
" nextag.vim - Move to next and previous tags in a SGML document, including
" XML and HTML. Use <leader>. and <leader>, to search for the next and
" previous tags, respectively. Prepended counts work, e.g. 5<leader>. as do
" operations, e.g. d<leader>. and visual mode e.g. v<leader>,.
"
" Maintainer: Tom Ryder <http://www.sanctum.geek.nz/>
"

"
" Wrapper to prevent overloading and signal our presence, and check we're not
" in compatible mode or running a version of Vim that's too old.
"
if exists('g:loaded_nextag') || &compatible || v:version < 700
    finish
endif
let g:loaded_nextag = 1

"
" Search for a SGML tag with the specified flag.
"
function! s:MoveToSGMLTag(direction, mode, count)
    if a:mode == 'v'
        normal! gv
    endif
    let l:visualfix = a:mode == 'v' && a:direction == 'next' && &selection != 'exclusive' ? 1 : 0
    for l:iteration in range(1, a:count)
        call search('\m<\/\?\w\+[^>]*>', a:direction == 'next' ? 'W' : 'Wb')
        if l:visualfix
            normal! l
        endif
    endfor
    if l:visualfix
        normal! h
    endif
endfunction

"
" Default remappings.
"
for s:mode in ['n', 'o', 'v']
    execute s:mode . 'map <silent> <leader>. :<C-U>call <SID>MoveToSGMLTag("next", "' . s:mode . '", v:count1)<CR>'
    execute s:mode . 'map <silent> <leader>, :<C-U>call <SID>MoveToSGMLTag("prev", "' . s:mode . '", v:count1)<CR>'
endfor