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, 22:47 UTC
Message-ID
<d2e97e800809071547m2b2e0f82ycc370f048d826b2d@mail.gmail.com>
In-Reply-To
<20080907131356.GC3387@mithlond.arda.local>
Show 14 quoted lines
>> If you alter the RunShellCommand() function to the following -
>
>>       if stridx(a:cmdline, "diff") > 0
>>           set filetype=diff
>>       endif
>
>> 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

Vim 7.2 provides a better alternative. If the command is specifically 'git' then setting the filetype to 'git' also provides the correct syntax highlighting.

For example,
  if v:version >= 702
      if stridx(a:cmdline, "git") == 0
          setlocal filetype=git
      endif
  endif
Syntax highlighting is displayed correctly for several commands including:
  :Git diff
  :Git show
  :Git log

And possibly others. If Vim (7.2) is your default editor when performing a "git commit" then there is also a new built in Vim command -

  :DiffGitCached

This opens a preview window with the contents of "git diff --cached". The :DiffGitCached command is only available when filetype=gitcommit.

Perhaps some of these ideas should be added to the Vim wiki...
http://vim.wikia.com/wiki/Display_shell_commands%27_output_on_Vim_window
Previous: Teemu LikonenNext: Teemu Likonen
Message 5 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.