Re: Extremely simple Vim interface for Git
- From
- Teemu Likonen <tlikonen@iki.fi>
- Date
- Sep 7, 2008, 17:46 UTC
- Message-ID
- <20080907174650.GA3404@mithlond.arda.local>
- In-Reply-To
- <20080907131356.GC3387@mithlond.arda.local>
Teemu Likonen wrote (2008-09-07 16:13 +0300):
Show 8 quoted lines
> > 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
endifIt 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