diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2012-02-11 04:15:34 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2012-02-11 04:15:34 +1300 |
commit | 8a35f8424e49a770affd530ac68c7da5ebc82f65 (patch) | |
tree | f6397c89067401ff3f7f71a06cdc1e87b20dadb6 /plugin | |
download | vim-nextag-8a35f8424e49a770affd530ac68c7da5ebc82f65.tar.gz vim-nextag-8a35f8424e49a770affd530ac68c7da5ebc82f65.zip |
First commit.
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/nextag.vim | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/plugin/nextag.vim b/plugin/nextag.vim new file mode 100644 index 0000000..d9493c6 --- /dev/null +++ b/plugin/nextag.vim @@ -0,0 +1,48 @@ +" +" nextag.vim - Move to next and previous tags in a SGML document, including +" XML and HTML. Use <leader>, and <leader>. to search for the previous and +" next HTML tags, respectively. Prepended counts work, e.g. 5<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:flags = (a:direction == "next") ? "W" : "Wb" + for l:iteration in range(1, a:count) + call search("<\w*[^>]*>", l:flags) + if a:mode == 'v' + if a:direction == 'next' && &selection != 'exclusive' + normal! l + endif + endif + endfor + if a:mode == 'v' + if a:direction == 'next' && &selection != 'exclusive' + normal! h + endif + 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 + |