Re: Extremely simple Vim interface for Git

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Teemu Likonen wrote (2008-09-07 16:13 +0300):

> > 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux