我找到了这一功能
" 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
阅读这个函数,我想我需要一些额外的set选项来测试,就像他们用&dif做的那样,但是使用了可视选项。类似于:
function! DiffToggle()
if &dif
diffoff
elseif &visual
Linediff
else
diffthis
endif
:endfunction这不起作用,但有没有人有任何线索让它发挥作用?此外,它将非常有用的任何参考,关于什么和多少这类设置变量是在vim。
编辑I在我的vimrc (Works)中得到了这样的结果:
"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发布于 2015-06-12 15:22:44
只需调用一个与xnoremap <Leader>df ...稍有不同的函数?当您处于可视模式时,将调用该功能。
或者,将模式作为参数传递给您的函数:
nnoremap <silent> <Leader>df :call DiffToggle('n')<CR>
xnoremap <silent> <Leader>df :call DiffToggle('x')<CR>..。并检查函数中的a:mode,其原型如下:
function! DiffToggle(mode)https://stackoverflow.com/questions/30801562
复制相似问题