git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Extremely simple Vim interface for Git

From
TLTeemu 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
    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
Previous: Teemu LikonenNext: Michael Wookey
Message 4 of 11 in “Extremely simple Vim interface for Git”
  1. Teemu LikonenSep 6, 2008
  2. Michael WookeySep 7, 2008
  3. Teemu LikonenSep 7, 2008
  4. Teemu LikonenSep 7, 2008
  5. Michael WookeySep 7, 2008
  6. Teemu LikonenSep 8, 2008
  7. Thomas AdamSep 7, 2008
  8. Teemu LikonenSep 7, 2008
  9. Thomas AdamSep 7, 2008
  10. Bob HiestandSep 8, 2008
  11. Peter Valdemar Mørch (Lists)Sep 9, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.