Re: Extremely simple Vim interface for Git
From: Teemu Likonen <hidden>
Date: 2016-06-15 22:45:19
Teemu Likonen wrote (2008-09-07 16:13 +0300):
quoted
Then Vim will apply diff syntax highlighting to the scratch buffer when a "diff" command is executed.Good idea. I implemented the same thing this way: if match(a:cmdline,'\v^(git|hg|svn|bzr) diff') >= 0 setlocal filetype=diff endif
Or even better, detect by the content:
if search('\m\C^--- .*\n+++ .*\n@@','n')
setlocal filetype=diff
endif
It works with things like "git show" and "git log -p" too. Here's
updated version for those who are interested:
command! -complete=file -nargs=* Git call s:RunShellCommand('git '.<q-args>)
" To run any shell command:
"command! -complete=file -nargs=+ Shell call s:RunShellCommand(<q-args>)
" Additional $VCS commands:
"command! -complete=file -nargs=* Hg call s:RunShellCommand('hg '.<q-args>)
"command! -complete=file -nargs=* Svn call s:RunShellCommand('svn '.<q-args>)
"command! -complete=file -nargs=* Bzr call s:RunShellCommand('bzr '.<q-args>)
" In case a shell command wants to open $EDITOR we use something
" that works from inside Vim.
let $EDITOR = '/usr/bin/gvim --nofork'
function! s:RunShellCommand(cmdline)
botright new
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
call setline(1,a:cmdline)
call setline(2,substitute(a:cmdline,'.','=','g'))
execute 'silent $read !'.escape(a:cmdline,'()%#')
setlocal nomodifiable
if search('\m\C^--- .*\n+++ .*\n@@','n')
setlocal filetype=diff
endif
1
endfunction