git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Teemu Likonen <tlikonen@iki.fi>
To: Michael Wookey <michaelwookey@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Extremely simple Vim interface for Git
Date: Sun, 7 Sep 2008 20:46:50 +0300	[thread overview]
Message-ID: <20080907174650.GA3404@mithlond.arda.local> (raw)
In-Reply-To: <20080907131356.GC3387@mithlond.arda.local>

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

  reply	other threads:[~2008-09-07 17:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-06 19:37 Extremely simple Vim interface for Git Teemu Likonen
2008-09-07 10:32 ` Michael Wookey
2008-09-07 13:13   ` Teemu Likonen
2008-09-07 17:46     ` Teemu Likonen [this message]
2008-09-07 22:47     ` Michael Wookey
2008-09-08  5:26       ` Teemu Likonen
2008-09-07 13:23 ` Thomas Adam
2008-09-07 13:59   ` Teemu Likonen
2008-09-07 14:11     ` Thomas Adam
2008-09-08 17:41   ` Bob Hiestand
2008-09-09  6:26     ` "Peter Valdemar Mørch (Lists)"

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080907174650.GA3404@mithlond.arda.local \
    --to=tlikonen@iki.fi \
    --cc=git@vger.kernel.org \
    --cc=michaelwookey@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).