From 855b57077e0dddb2380ea3614999980b24e384e3 Mon Sep 17 00:00:00 2001 From: Tom McDonald Date: Sat, 21 Dec 2013 22:51:50 -0500 Subject: [PATCH] Allow default mappings to be overridden Partial solution to #11 --- plugin/exchange.vim | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugin/exchange.vim b/plugin/exchange.vim index ea95b81..98e136c 100644 --- a/plugin/exchange.vim +++ b/plugin/exchange.vim @@ -129,6 +129,12 @@ function! s:store_pos(start, end) return [getpos(a:start), getpos(a:end)] endfunction +function! s:create_map(mode, lhs, rhs) + if !hasmapto(a:rhs, a:mode) + execute a:mode.'map '.a:lhs.' '.a:rhs + endif +endfunction + nnoremap Exchange :set opfunc=exchange_setg@ vnoremap Exchange :call exchange_set(visualmode(), 1) nnoremap ExchangeClear :call exchange_clear() @@ -138,7 +144,7 @@ if exists('g:exchange_no_mappings') finish endif -nmap cx Exchange -vmap cx Exchange -nmap cxc ExchangeClear -nmap cxx ExchangeLine +call s:create_map('n', 'cx', 'Exchange') +call s:create_map('v', 'cx', 'Exchange') +call s:create_map('n', 'cxc', 'ExchangeClear') +call s:create_map('v', 'cxx', 'ExchangeLine')