From 9838820f22e8da1069f19e02e0a9ef30c61bc99a Mon Sep 17 00:00:00 2001 From: "Harish.K" Date: Wed, 21 Sep 2016 14:15:26 +0530 Subject: [PATCH 1/2] Feature: create a function for jumping to matching pair changes: * if tag match was not success, search fun will return [-1,-1]. Be consistent with the return type of search function. * Call that searchFunction for both highlighting and jumping b/w tags --- ftplugin/html.vim | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/ftplugin/html.vim b/ftplugin/html.vim index 2143828..cc28b53 100644 --- a/ftplugin/html.vim +++ b/ftplugin/html.vim @@ -10,7 +10,7 @@ augroup matchhtmlparen autocmd! CursorMoved,CursorMovedI,WinEnter call s:Highlight_Matching_Pair() augroup END -fu! s:Highlight_Matching_Pair() +fu! s:Get_target_postition() " Remove any previous match. if exists('w:tag_hl_on') && w:tag_hl_on 2match none @@ -20,18 +20,32 @@ fu! s:Highlight_Matching_Pair() " Avoid that we remove the popup menu. " Return when there are no colors (looks like the cursor jumps). if pumvisible() || (&t_Co < 8 && !has("gui_running")) - return + return [ -1, -1 ] endif "get html tag under cursor let tagname = s:GetCurrentCursorTag() - if tagname == ""|return|endif + if tagname == "" + return [ -1, -1 ] + endif if tagname[0] == '/' let position = s:SearchForMatchingTag(tagname[1:], 0) else let position = s:SearchForMatchingTag(tagname, 1) endif + return position +endfu + +fu! s:Jumpto_Matching_Pair() + let position = s:Get_target_postition() + if position == [ -1, -1]|return|endif + call cursor(position) +endfu + +fu! s:Highlight_Matching_Pair() + let position = s:Get_target_postition() + if position == [ -1, -1]|return|endif call s:HighlightTagAtPosition(position) endfu @@ -78,16 +92,14 @@ fu! s:SearchForMatchingTag(tagname, forwards) " The searchpairpos() timeout parameter was added in 7.2 if v:version >= 702 - return searchpairpos(starttag, midtag, endtag, flags, skip, stopline, timeout) + let position = searchpairpos(starttag, midtag, endtag, flags, skip, stopline, timeout) else - return searchpairpos(starttag, midtag, endtag, flags, skip, stopline) + let position = searchpairpos(starttag, midtag, endtag, flags, skip, stopline) endif + return position endfu fu! s:HighlightTagAtPosition(position) - if a:position == [0, 0] - return - endif let [m_lnum, m_col] = a:position exe '2match MatchParen /\(\%' . m_lnum . 'l\%' . m_col . 'c<\zs.\{-}\ze[\n >]\)\|' @@ -97,4 +109,6 @@ fu! s:HighlightTagAtPosition(position) let w:tag_hl_on = 1 endfu +nmap % :call Jumpto_Matching_Pair() + " vim: set ts=8 sts=4 sw=4 expandtab : From 3ee54eb8f674fefa1d37cad52c89ff4a5fddfdc2 Mon Sep 17 00:00:00 2001 From: "Harish.K" Date: Thu, 29 Sep 2016 19:07:37 +0530 Subject: [PATCH 2/2] Fix: support for visual mode movement --- ftplugin/html.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ftplugin/html.vim b/ftplugin/html.vim index cc28b53..8098e30 100644 --- a/ftplugin/html.vim +++ b/ftplugin/html.vim @@ -37,7 +37,11 @@ fu! s:Get_target_postition() return position endfu -fu! s:Jumpto_Matching_Pair() +fu! s:Jumpto_Matching_Pair( vis ) + if a:vis + echo 'visssss' + normal! gv + endif let position = s:Get_target_postition() if position == [ -1, -1]|return|endif call cursor(position) @@ -109,6 +113,7 @@ fu! s:HighlightTagAtPosition(position) let w:tag_hl_on = 1 endfu -nmap % :call Jumpto_Matching_Pair() +nmap % :call Jumpto_Matching_Pair(0) +vmap % :call Jumpto_Matching_Pair(1) " vim: set ts=8 sts=4 sw=4 expandtab :