From 36673b255bb0b877063d0a3bb401930521d6b60b Mon Sep 17 00:00:00 2001 From: Tom McDonald Date: Sat, 14 Feb 2015 10:56:16 -0500 Subject: [PATCH] Allow toggling of exchange region highlighting Closes #33 --- plugin/exchange.vim | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plugin/exchange.vim b/plugin/exchange.vim index 8717ac1..c564ca2 100644 --- a/plugin/exchange.vim +++ b/plugin/exchange.vim @@ -1,3 +1,5 @@ +let s:enable_highlighting = 1 + function! s:exchange(x, y, reverse, expand) let reg_z = s:save_reg('z') let reg_unnamed = s:save_reg('"') @@ -143,7 +145,7 @@ endfunction function! s:highlight_region(region) let pattern = '\%'.a:region[0].'l\%'.a:region[1].'v\_.\{-}\%'.a:region[2].'l\(\%>'.a:region[3].'v\|$\)' - return matchadd('ExchangeRegion', pattern) + return matchadd('_exchange_region', pattern) endfunction function! s:highlight_clear(match) @@ -152,6 +154,15 @@ function! s:highlight_clear(match) endfor endfunction +function! s:highlight_toggle(...) + if a:0 == 1 + let s:enable_highlighting = a:1 + else + let s:enable_highlighting = !s:enable_highlighting + endif + execute 'highlight link _exchange_region' (s:enable_highlighting ? 'ExchangeRegion' : 'None') +endfunction + " Return < 0 if x comes before y in buffer, " = 0 if x and y overlap in buffer, " > 0 if x comes after y in buffer @@ -228,6 +239,10 @@ vnoremap (Exchange) :call exchange_set(visualmode(), 1) nnoremap (ExchangeClear) :call exchange_clear() nnoremap (ExchangeLine) :set opfunc=exchange_setg@_ +command! XchangeHighlightToggle call s:highlight_toggle() +command! XchangeHighlightEnable call s:highlight_toggle(1) +command! XchangeHighlightDisable call s:highlight_toggle(0) + command! ExchangeClear call s:exchange_clear(1) command! XchangeClear call s:exchange_clear()