From 8a35f8424e49a770affd530ac68c7da5ebc82f65 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 11 Feb 2012 04:15:34 +1300 Subject: First commit. --- README | 12 ++++++++++++ doc/nextag.txt | 19 +++++++++++++++++++ doc/tags | 5 +++++ plugin/nextag.vim | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 README create mode 100644 doc/nextag.txt create mode 100644 doc/tags create mode 100644 plugin/nextag.vim diff --git a/README b/README new file mode 100644 index 0000000..27bcb6a --- /dev/null +++ b/README @@ -0,0 +1,12 @@ +nextag - SGML tag motions (XML, XHTML, HTML etc) + +Author: Tom Ryder +License: Same terms as Vim itself (see |license|) + +Navigate forward and backward by tags, just like a normal Vim motion. +Operators and counts can be prepended, and it also works in visual mode. + +{operator}{count}\. Move to start of next tag, if one exists. + +{operator}{count}\, Move to start of previous tag, if one exists. + diff --git a/doc/nextag.txt b/doc/nextag.txt new file mode 100644 index 0000000..92fb46d --- /dev/null +++ b/doc/nextag.txt @@ -0,0 +1,19 @@ +*nextag.txt* SGML tag motions (XML, XHTML, HTML etc) + +Author: Tom Ryder +License: Same terms as Vim itself (see |license|) + +DESCRIPTION *nextag* + +Navigate forward and backward by tags, just like a normal Vim motion. +Operators and counts can be prepended, and it also works in visual mode. + +MAPPINGS *nextag-mappings* + + *\.* +{operator}{count}\. Move to start of next tag, if one exists. + + *\,* +{operator}{count}\, Move to start of previous tag, if one exists. + + vim:tw=78:et:ft=help:norl: diff --git a/doc/tags b/doc/tags new file mode 100644 index 0000000..b537b68 --- /dev/null +++ b/doc/tags @@ -0,0 +1,5 @@ +\, nextag.txt /*\\,* +\. nextag.txt /*\\.* +nextag nextag.txt /*nextag* +nextag-mappings nextag.txt /*nextag-mappings* +nextag.txt nextag.txt /*nextag.txt* 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 , and . to search for the previous and +" next HTML tags, respectively. Prepended counts work, e.g. 5. +" +" Maintainer: Tom Ryder +" + +" +" 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 . :call MoveToSGMLTag("next", "' . s:mode . '", v:count1)' + execute s:mode . 'map , :call MoveToSGMLTag("prev", "' . s:mode . '", v:count1)' +endfor + -- cgit v1.2.3