diff options
| author | Teddy Wing | 2019-06-03 21:58:21 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2019-06-03 21:58:21 +0200 | 
| commit | cea8855836335942886b4e2a3fea4a3d7d549b3c (patch) | |
| tree | 70027c5929851d2133b0f03c2001e6519aa39c31 /bundle/diff-corrections | |
| parent | 7d7c2b7e47f836c7e1be3ba63a6b5a6533e87c78 (diff) | |
| download | dotvim-cea8855836335942886b4e2a3fea4a3d7d549b3c.tar.bz2 | |
diff_corrections: Add `cx` mapping to close tab
Add a mapping to quickly close a tab. Makes it easier to close files
that I've finished reviewing.
Thanks to user9433424
(https://vi.stackexchange.com/users/6960/user9433424) on the Vi Stack
Exchange for the very detailed explanation of how to restore a mapping:
https://vi.stackexchange.com/questions/7734/how-to-save-and-restore-a-mapping/7735#7735
Using user9433424's mapping restore code, and ignoring the case where a
mapping is defined both globally and local to a buffer.
Diffstat (limited to 'bundle/diff-corrections')
| -rw-r--r-- | bundle/diff-corrections/autoload/diff_corrections.vim | 26 | 
1 files changed, 26 insertions, 0 deletions
| diff --git a/bundle/diff-corrections/autoload/diff_corrections.vim b/bundle/diff-corrections/autoload/diff_corrections.vim index 620c1b0..c3003e9 100644 --- a/bundle/diff-corrections/autoload/diff_corrections.vim +++ b/bundle/diff-corrections/autoload/diff_corrections.vim @@ -1,4 +1,6 @@  let s:old_cursorline = &cursorline +let s:restore_cx_mapping = '' +  function! diff_corrections#Run()  	if &diff @@ -7,12 +9,18 @@ function! diff_corrections#Run()  		endif  		set nocursorline + +		nnoremap cx :<C-u>tabclose<CR>  	else  		if exists('g:colors_name') && g:colors_name ==# 'twilight256'  			execute 'highlight ' . s:old_highlight_comment  		endif  		let &cursorline = s:old_cursorline + +		if strlen(s:restore_cx_mapping) > 0 +			execute s:restore_cx_mapping +		endif  	endif  endfunction @@ -32,4 +40,22 @@ function! s:SaveCommentColor()  endfunction +function! s:SaveMapping() +	let mapping = maparg('cx', 'n', 0, 1) + +	if !empty(mapping) +		let s:restore_cx_mapping .= (mapping.noremap ? 'nnoremap' : 'nmap') . +			\ join( +				\ map( +					\ ['buffer', 'expr', 'nowait', 'silent'], +					\ 'mapping[v:val] ? "<" . v:val . ">" : ""' +				\ ) +			\ ) . +			\ mapping.lhs . ' ' . +			\ substitute(mapping.rhs, '<SID>', '<SNR>' . mapping.sid . '_', 'g') +	endif +endfunction + +  let s:old_highlight_comment = s:SaveCommentColor() +call s:SaveMapping() | 
