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

Re: Extremely simple Vim interface for Git

From
Michael Wookey <michaelwookey@gmail.com>
Date
Sep 7, 2008, 10:32 UTC
Message-ID
<d2e97e800809070332t35e4ed46u7af4653ea768b39b@mail.gmail.com>
In-Reply-To
<20080906193744.GA3122@mithlond.arda.local>
Show 20 quoted lines
> Here's a very simple idea for using Git from Vim editor. Add these lines
> to your ~/.vimrc file:
>
>
>    command! -complete=file -nargs=* Git   call s:RunShellCommand('git '.<q-args>)
>    command! -complete=file -nargs=* Svn   call s:RunShellCommand('svn '.<q-args>)
>    command! -complete=file -nargs=+ Shell call s:RunShellCommand(<q-args>)
>
>    let $EDITOR = '/usr/bin/gvim --nofork'
>
>    function! s:RunShellCommand(cmdline)
>        botright new
>        setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile
>        setlocal nowrap
>        call setline(1,a:cmdline)
>        call setline(2,substitute(a:cmdline,'.','=','g'))
>        execute 'silent 2read !'.escape(a:cmdline,'()%#')
>        setlocal nomodifiable
>        1
>    endfunction
If you alter the RunShellCommand() function to the following -
  function! s:RunShellCommand(cmdline)
      botright new
      setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile
      setlocal nowrap
      if stridx(a:cmdline, "diff") > 0
          set filetype=diff
      endif
      execute 'silent 0read !'.escape(a:cmdline,'%#')
      setlocal nomodifiable
      1
  endfunction

Then Vim will apply diff syntax highlighting to the scratch buffer when a "diff" command is executed.

For example:
  :Git diff
  :Git diff --cached
etc..
Previous: Teemu LikonenNext: Teemu Likonen
Message 2 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.