我发现this function:编程DIFF vim的功能,VIM DIFF映射
" Set up a keymapping from <Leader>df to a function call.
" (Note the function doesn't need to be defined beforehand.)
" Run this mapping silently. That is, when I call this mapping,
" don't bother showing "call DiffToggle()" on the command line.
nnoremap <silent> <Leader>df :call DiffToggle()<CR>
" Define a function called DiffToggle.
" The ! overwrites any existing definition by this name.
function! DiffToggle()
" Test the setting 'diff', to see if it's on or off.
" (Any :set option can be tested with &name.
" See :help expr-option.)
if &diff
diffoff
else
diffthis
endif
:endfunction
现在我想添加一个额外的条件,如果有一些选择的文本(可视化模式)调用另一个命令,而不是diffthis
,Linediff
阅读功能我想我需要一些额外的设置选项来测试,就像他们用&dif
,但与视觉选项。类似于:
function! DiffToggle()
if &dif
diffoff
elseif &visual
Linediff
else
diffthis
endif
:endfunction
这不起作用,但没有人有任何线索使其工作? 此外,任何有关这种类型的设置变量以及vim中的多少个设置变量的参考都会非常有用。
编辑 我在的vimrc结束了这一点,(工程):
"LINEDIFF/VIMDIFF
"--------------
nnoremap <silent> <Leader>df :call DiffToggle('n')<CR>
xnoremap <silent> <Leader>df :call DiffToggle('x')<CR>
function! DiffToggle(mode) range
echo "difftoggle..."
if &diff
diffoff
echo "diffoff..."
else
if a:mode=='x'
echo "linediff..."
echo a:firstline."---".a:lastline
call linediff#Linediff(a:firstline, a:lastline)
else
echo "diff..."
diffthis
endif
endif
:endfunction
'ELSEIF有( '视觉' )'? ':help has()' –
或者如果你需要检查当前模式(visual,insert,normal等),调用'mode()'。 –
has()只会告诉你该功能是否受支持,所以在我的情况下总是返回1 – vivoconunxino