我找到了this function:
" 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
但使用visual选项一样。类似的东西:
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
答案 0 :(得分:3)
只需拨打xnoremap <Leader>df ...
稍微不同的功能即可?当您处于可视模式时,将调用该文件。
或者,将模式作为参数传递给您的函数:
nnoremap <silent> <Leader>df :call DiffToggle('n')<CR>
xnoremap <silent> <Leader>df :call DiffToggle('x')<CR>
...并检查您的函数中的a:mode
,具有以下原型:
function! DiffToggle(mode)