我發現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