threads / patch / 15651

patchvim syntax: highlight the diff in commit message template

Subject: [PATCH] vim syntax: highlight the diff in commit message template

## tl;dr

14 messages between Sep 24, 2008 and Sep 30, 2008. Diffs are folded; open one to read it.

replies: 13people: 6as markdown or json

SZEDER Gábor· Sep 24, 2008, 15:22 UTC · lore
The template generated by 'git commit -v' is much easier to read now.
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/vim/syntax/gitcommit.vim |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
Show changes to contrib/vim/syntax/gitcommit.vim +2 −0
diff --git a/contrib/vim/syntax/gitcommit.vim b/contrib/vim/syntax/gitcommit.vim
index 332121b..0872e65 100644
--- a/contrib/vim/syntax/gitcommit.vim
+++ b/contrib/vim/syntax/gitcommit.vim
@@ -16,3 +16,5 @@ hi def link gitUntracked Comment
 hi def link gitCommitFile Type
 hi def link gitChangedFile Constant
 hi def link gitUntrackedFile Constant
+
+source $VIMRUNTIME/syntax/diff.vim
-- 
1.6.0.2.323.gb1a20
Jeff King· Sep 24, 2008, 15:57 UTC · re: SZEDER Gábor · lore

Re: [PATCH] vim syntax: highlight the diff in commit message template

On Wed, Sep 24, 2008 at 05:22:06PM +0200, SZEDER Gábor wrote:
> The template generated by 'git commit -v' is much easier to read now.

I think the goal of this change is good, but I'm not sure about the implementation:

> +source $VIMRUNTIME/syntax/diff.vim

Despite having written the original gitcommit.vim, I am largely clueless about vim syntax highlighting. However, the gitcommit.vim shipped with vim 7.2 does this:

  syn include @gitcommitDiff syntax/diff.vim
  syn region gitcommitDiff start=/\%(^diff --git \)\@=/ end=/^$\|^#\@=/ contains=@gitcommitDiff

which seems a bit more robust to me. I have no idea if that syntax introduces any limitations about which versions of vim can be used.

However, this brings up a more important question: is there any reason for git to ship a vim syntax file when there is already a maintained (and IMHO, much superior) one that ships with vim? The only people who should need our file are people on versions of vim older than the ones that ship gitcommit.vim. For those people, I suspect they are better off going to vim.org and grabbing the up to date (and undoubtedly more carefully constructed) syntax file rather than pulling what is in our contrib/ area.

Is there any objection to simply removing it (and probably replacing it with a note to go look at the official highlighting file)?

-Peff
SZEDER Gábor· Sep 24, 2008, 17:01 UTC · re: Jeff King · lore

Re: [PATCH] vim syntax: highlight the diff in commit message template

Hi,
On Wed, Sep 24, 2008 at 11:57:45AM -0400, Jeff King wrote:
> Is there any objection to simply removing it (and probably replacing it
> with a note to go look at the official highlighting file)?

I'm for it, because I didn't know that there is an official git syntax highlight file out there. Indeed, I haven't even know that vim 7.2 is out.

Thanks, Gábor

Jeff King· Sep 24, 2008, 17:53 UTC · re: SZEDER Gábor · lore

[RFC/PATCH] remove vim syntax highlighting in favor of upstream

[Tim Pope cc'd as the author of the official version. Tim: just an FYI, but if you have any comments, please feel free to share]

[Shawn cc'd as the interim maintainer. I, for one, welcome our new Java-programming overlords].

On Wed, Sep 24, 2008 at 07:01:54PM +0200, SZEDER Gábor wrote:
Show 5 quoted lines
> > Is there any objection to simply removing it (and probably replacing it
> > with a note to go look at the official highlighting file)?
> I'm for it, because I didn't know that there is an official git syntax
> highlight file out there.  Indeed, I haven't even know that vim 7.2 is
> out.

Here is a patch, then. Shawn, we should probably give any vim users a few days to object in case there is something they don't like about the upstream version, but other than that, I think this should be applied to master.

-- >8 -- remove vim syntax highlighting in favor of upstream

As of version 7.2, vim ships with its own syntax highlighting for git commit messages, which is:

  1. more comprehensive in splitting up the various
     components of the file
  2. in accordance with the usual vim behavior for syntax
     highlighting (e.g., respecting b:current_syntax)
  3. presumably better maintained (I have not been using
     what's in git's contrib/ directory for some time in
     favor of the upstream version)
This patch gets rid of our local version and just points
interested parties to the upstream version.
---
 contrib/vim/README               |   13 +++++++++++--
 contrib/vim/syntax/gitcommit.vim |   18 ------------------
 2 files changed, 11 insertions(+), 20 deletions(-)
 delete mode 100644 contrib/vim/syntax/gitcommit.vim
Show changes to 2 files +11 −20

contrib/vim/README, contrib/vim/syntax/gitcommit.vim

diff --git a/contrib/vim/README b/contrib/vim/README
index 9e7881f..12d61bb 100644
--- a/contrib/vim/README
+++ b/contrib/vim/README
@@ -1,8 +1,17 @@
-To syntax highlight git's commit messages, you need to:
-  1. Copy syntax/gitcommit.vim to vim's syntax directory:
+Syntax highlighting for git commit messages is included with the vim
+distribution as of vim 7.2, and should work automatically.
+
+If you have an older version of vim, you can get the latest syntax file
+from the vim project:
+
+  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/gitcommit.vim
+
+To install:
+
+  1. Copy gitcommit.vim to vim's syntax directory:
      $ mkdir -p $HOME/.vim/syntax
      $ cp syntax/gitcommit.vim $HOME/.vim/syntax
   2. Auto-detect the editing of git commit files:
      $ cat >>$HOME/.vimrc <<'EOF'
      autocmd BufNewFile,BufRead COMMIT_EDITMSG set filetype=gitcommit
      EOF
diff --git a/contrib/vim/syntax/gitcommit.vim b/contrib/vim/syntax/gitcommit.vim
deleted file mode 100644
index 332121b..0000000
--- a/contrib/vim/syntax/gitcommit.vim
+++ /dev/null
@@ -1,18 +0,0 @@
-syn region gitLine start=/^#/ end=/$/
-syn region gitCommit start=/^# Changes to be committed:$/ end=/^#$/ contains=gitHead,gitCommitFile
-syn region gitHead contained start=/^#   (.*)/ end=/^#$/
-syn region gitChanged start=/^# Changed but not updated:/ end=/^#$/ contains=gitHead,gitChangedFile
-syn region gitUntracked start=/^# Untracked files:/ end=/^#$/ contains=gitHead,gitUntrackedFile
-
-syn match gitCommitFile contained /^#\t.*/hs=s+2
-syn match gitChangedFile contained /^#\t.*/hs=s+2
-syn match gitUntrackedFile contained /^#\t.*/hs=s+2
-
-hi def link gitLine Comment
-hi def link gitCommit Comment
-hi def link gitChanged Comment
-hi def link gitHead Comment
-hi def link gitUntracked Comment
-hi def link gitCommitFile Type
-hi def link gitChangedFile Constant
-hi def link gitUntrackedFile Constant
-- 
1.6.0.2.473.g126a14
Shawn O. Pearce· Sep 24, 2008, 18:07 UTC · re: Jeff King · lore

Re: [RFC/PATCH] remove vim syntax highlighting in favor of upstream

Jeff King <peff@peff.net> wrote:
> [Shawn cc'd as the interim maintainer. I, for one, welcome our
> new Java-programming overlords].
Heh.
 
> Here is a patch, then. Shawn, we should probably give any vim users a
> few days to object in case there is something they don't like about the
> upstream version, but other than that, I think this should be applied to
> master.

Thanks. Its queued in my pile of patches waiting for ACKs and/or comments before I actually apply them to my tree. I'll let it sit for a little, but I think we want to apply it.

Show 18 quoted lines
> -- >8 --
> remove vim syntax highlighting in favor of upstream
> 
> As of version 7.2, vim ships with its own syntax
> highlighting for git commit messages, which is:
> 
>   1. more comprehensive in splitting up the various
>      components of the file
> 
>   2. in accordance with the usual vim behavior for syntax
>      highlighting (e.g., respecting b:current_syntax)
> 
>   3. presumably better maintained (I have not been using
>      what's in git's contrib/ directory for some time in
>      favor of the upstream version)
> 
> This patch gets rid of our local version and just points
> interested parties to the upstream version.
-- 
Shawn.
Garry Dolley· Sep 24, 2008, 18:39 UTC · re: Jeff King · lore

Re: [RFC/PATCH] remove vim syntax highlighting in favor of upstream

On Wed, Sep 24, 2008 at 01:53:15PM -0400, Jeff King wrote:
Show 18 quoted lines
> [Tim Pope cc'd as the author of the official version. Tim: just an FYI,
> but if you have any comments, please feel free to share]
> 
> [Shawn cc'd as the interim maintainer. I, for one, welcome our
> new Java-programming overlords].
> 
> On Wed, Sep 24, 2008 at 07:01:54PM +0200, SZEDER Gábor wrote:
> 
> > > Is there any objection to simply removing it (and probably replacing it
> > > with a note to go look at the official highlighting file)?
> > I'm for it, because I didn't know that there is an official git syntax
> > highlight file out there.  Indeed, I haven't even know that vim 7.2 is
> > out.
> 
> Here is a patch, then. Shawn, we should probably give any vim users a
> few days to object in case there is something they don't like about the
> upstream version, but other than that, I think this should be applied to
> master.

As a Vim user, I think removing the syntax file, and giving a reference to the official one, is fine.

-- 
Garry Dolley
ARP Networks, Inc.
http://scie.nti.st
Los Angeles County REACT, Unit 336
WQGK336
SZEDER Gábor· Sep 24, 2008, 19:56 UTC · re: Jeff King · lore

Re: [RFC/PATCH] remove vim syntax highlighting in favor of upstream

Hi,
On Wed, Sep 24, 2008 at 01:53:15PM -0400, Jeff King wrote:
Show 7 quoted lines
> +Syntax highlighting for git commit messages is included with the vim
> +distribution as of vim 7.2, and should work automatically.
> +
> +If you have an older version of vim, you can get the latest syntax file
> +from the vim project:
> +
> +  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/gitcommit.vim

vim 7.2 provides support not only for commit messages but also for other git-related filetypes. I think it would be good to mention them, too, therefore I extended your patch with them.

-- >8 -- remove vim syntax highlighting in favor of upstream

As of version 7.2, vim ships with its own syntax highlighting for git commit messages, which is:

  1. more comprehensive in splitting up the various
     components of the file
  2. in accordance with the usual vim behavior for syntax
     highlighting (e.g., respecting b:current_syntax)
  3. presumably better maintained (I have not been using
     what's in git's contrib/ directory for some time in
     favor of the upstream version)

Furthermore, vim 7.2 also provides syntax highlighting for other git filetypes (gitconfig, rebase, send-email).

This patch gets rid of our local version and just points interested parties to the upstream version.

The code for auto-detecting filetypes is taken from vim 7.2's runtime/filetype.vim.

---
 contrib/vim/README               |   38 ++++++++++++++++++++++++++++++--------
 contrib/vim/syntax/gitcommit.vim |   18 ------------------
 2 files changed, 30 insertions(+), 26 deletions(-)
 delete mode 100644 contrib/vim/syntax/gitcommit.vim
Show changes to 2 files +30 −26

contrib/vim/README, contrib/vim/syntax/gitcommit.vim

diff --git a/contrib/vim/README b/contrib/vim/README
index 9e7881f..a811675 100644
--- a/contrib/vim/README
+++ b/contrib/vim/README
@@ -1,8 +1,30 @@
-To syntax highlight git's commit messages, you need to:
-  1. Copy syntax/gitcommit.vim to vim's syntax directory:
-     $ mkdir -p $HOME/.vim/syntax
-     $ cp syntax/gitcommit.vim $HOME/.vim/syntax
-  2. Auto-detect the editing of git commit files:
-     $ cat >>$HOME/.vimrc <<'EOF'
-     autocmd BufNewFile,BufRead COMMIT_EDITMSG set filetype=gitcommit
-     EOF
+Syntax highlighting for git commit messages, config files, etc. is
+included with the vim distribution as of vim 7.2, and should work
+automatically.
+
+If you have an older version of vim, you can get the latest syntax
+files from the vim project:
+
+  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/git.vim
+  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/gitcommit.vim
+  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/gitconfig.vim
+  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/gitrebase.vim
+  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/gitsendemail.vim
+
+To install:
+
+  1. Copy these files to vim's syntax directory $HOME/.vim/syntax
+  2. Auto-detect the editing of various git-related filetypes:
+	$ cat >>$HOME/.vimrc <<'EOF'
+	autocmd BufNewFile,BufRead *.git/COMMIT_EDITMSG    setf gitcommit
+	autocmd BufNewFile,BufRead *.git/config,.gitconfig setf gitconfig
+	autocmd BufNewFile,BufRead git-rebase-todo         setf gitrebase
+	autocmd BufNewFile,BufRead .msg.[0-9]*
+		\ if getline(1) =~ '^From.*# This line is ignored.$' |
+		\   setf gitsendemail |
+		\ endif
+	autocmd BufNewFile,BufRead *.git/**
+		\ if getline(1) =~ '^\x\{40\}\>\|^ref: ' |
+		\   setf git |
+		\ endif
+	EOF
diff --git a/contrib/vim/syntax/gitcommit.vim b/contrib/vim/syntax/gitcommit.vim
deleted file mode 100644
index 332121b..0000000
--- a/contrib/vim/syntax/gitcommit.vim
+++ /dev/null
@@ -1,18 +0,0 @@
-syn region gitLine start=/^#/ end=/$/
-syn region gitCommit start=/^# Changes to be committed:$/ end=/^#$/ contains=gitHead,gitCommitFile
-syn region gitHead contained start=/^#   (.*)/ end=/^#$/
-syn region gitChanged start=/^# Changed but not updated:/ end=/^#$/ contains=gitHead,gitChangedFile
-syn region gitUntracked start=/^# Untracked files:/ end=/^#$/ contains=gitHead,gitUntrackedFile
-
-syn match gitCommitFile contained /^#\t.*/hs=s+2
-syn match gitChangedFile contained /^#\t.*/hs=s+2
-syn match gitUntrackedFile contained /^#\t.*/hs=s+2
-
-hi def link gitLine Comment
-hi def link gitCommit Comment
-hi def link gitChanged Comment
-hi def link gitHead Comment
-hi def link gitUntracked Comment
-hi def link gitCommitFile Type
-hi def link gitChangedFile Constant
-hi def link gitUntrackedFile Constant
Jeff King· Sep 24, 2008, 19:59 UTC · re: SZEDER Gábor · lore

Re: [RFC/PATCH] remove vim syntax highlighting in favor of upstream

On Wed, Sep 24, 2008 at 09:56:58PM +0200, SZEDER Gábor wrote:
> vim 7.2 provides support not only for commit messages but also for
> other git-related filetypes.  I think it would be good to mention
> them, too, therefore I extended your patch with them.
I think that is a sensible change.
-Peff
SZEDER Gábor· Sep 25, 2008, 12:48 UTC · re: SZEDER Gábor · lore

Re: [RFC/PATCH] remove vim syntax highlighting in favor of upstream

Hi,
OK, so I'm complaining a bit.
On Wed, Sep 24, 2008 at 09:56:58PM +0200, SZEDER Gábor wrote:
Show 17 quoted lines
> +To install:
> +
> +  1. Copy these files to vim's syntax directory $HOME/.vim/syntax
> +  2. Auto-detect the editing of various git-related filetypes:
> +	$ cat >>$HOME/.vimrc <<'EOF'
> +	autocmd BufNewFile,BufRead *.git/COMMIT_EDITMSG    setf gitcommit
> +	autocmd BufNewFile,BufRead *.git/config,.gitconfig setf gitconfig
> +	autocmd BufNewFile,BufRead git-rebase-todo         setf gitrebase
> +	autocmd BufNewFile,BufRead .msg.[0-9]*
> +		\ if getline(1) =~ '^From.*# This line is ignored.$' |
> +		\   setf gitsendemail |
> +		\ endif
> +	autocmd BufNewFile,BufRead *.git/**
> +		\ if getline(1) =~ '^\x\{40\}\>\|^ref: ' |
> +		\   setf git |
> +		\ endif
> +	EOF

There are issues with this second step. If I append this code to my .vimrc, then vim sometimes overrides the filetype with conf.

vim has a guessing rule for detecting conf files, which triggers if one of the first five lines of the file begins with a '#'. So if I start to write a new commit message or I interactively rebase 4 or less commits, then this rule triggers and vim overrides the git filetype with filetype conf. If I do a commit --amend with a long enough original commit message or an interactive rebase with more than 4 commit, then this rule no more triggers and everything is fine.

But what's really puzzling is that if I insert the above code into $VIMRUNTIME/filetype.vim (at the spot where it can be found in vim 7.2's filetype.vim), then everything works as expected, git filetypes are never overridden.

This is not related to the changes in this patch. git's original vim syntax highlight for commit messages has the exact same behaviour.

The first step is OK: it doesn't matter whether I put git-related syntax files under $HOME/.vim/syntax/ or under $VIMRUNTIME/syntax/.

I'm using vim 7.1.138 in Ubuntu 8.04.
Anyone have a clue?

Thanks, Gábor

Bob Hiestand· Sep 25, 2008, 14:00 UTC · re: SZEDER Gábor · lore

Re: [RFC/PATCH] remove vim syntax highlighting in favor of upstream

On Thu, Sep 25, 2008 at 7:48 AM, SZEDER Gábor <szeder@ira.uka.de> wrote:
Show 44 quoted lines
> Hi,
>
> OK, so I'm complaining a bit.
>
> On Wed, Sep 24, 2008 at 09:56:58PM +0200, SZEDER Gábor wrote:
>> +To install:
>> +
>> +  1. Copy these files to vim's syntax directory $HOME/.vim/syntax
>> +  2. Auto-detect the editing of various git-related filetypes:
>> +     $ cat >>$HOME/.vimrc <<'EOF'
>> +     autocmd BufNewFile,BufRead *.git/COMMIT_EDITMSG    setf gitcommit
>> +     autocmd BufNewFile,BufRead *.git/config,.gitconfig setf gitconfig
>> +     autocmd BufNewFile,BufRead git-rebase-todo         setf gitrebase
>> +     autocmd BufNewFile,BufRead .msg.[0-9]*
>> +             \ if getline(1) =~ '^From.*# This line is ignored.$' |
>> +             \   setf gitsendemail |
>> +             \ endif
>> +     autocmd BufNewFile,BufRead *.git/**
>> +             \ if getline(1) =~ '^\x\{40\}\>\|^ref: ' |
>> +             \   setf git |
>> +             \ endif
>> +     EOF
>
> There are issues with this second step.  If I append this code to my
> .vimrc, then vim sometimes overrides the filetype with conf.
>
> vim has a guessing rule for detecting conf files, which triggers if
> one of the first five lines of the file begins with a '#'.  So if I
> start to write a new commit message or I interactively rebase 4 or
> less commits, then this rule triggers and vim overrides the git
> filetype with filetype conf.  If I do a commit --amend with a long
> enough original commit message or an interactive rebase with more than
> 4 commit, then this rule no more triggers and everything is fine.
>
> But what's really puzzling is that if I insert the above code into
> $VIMRUNTIME/filetype.vim (at the spot where it can be found in vim
> 7.2's filetype.vim), then everything works as expected, git filetypes
> are never overridden.
>
> This is not related to the changes in this patch.  git's original vim
> syntax highlight for commit messages has the exact same behaviour.
>
> The first step is OK: it doesn't matter whether I put git-related
> syntax files under $HOME/.vim/syntax/ or under $VIMRUNTIME/syntax/.

I'd guess that your autocommands defined in .vimrc take effect after the default file type settings. When you use ':setf', it intentionally will not override the existing file type if one has already been detected.

Use ':help new-filetype' to see the various ways you can interact with and/or override the default filetype detection.

bob
Shawn O. Pearce· Sep 29, 2008, 14:55 UTC · re: SZEDER Gábor · lore

Re: [RFC/PATCH] remove vim syntax highlighting in favor of upstream

SZEDER GGGbor <szeder@ira.uka.de> wrote:
Show 29 quoted lines
> remove vim syntax highlighting in favor of upstream
> 
> As of version 7.2, vim ships with its own syntax
> highlighting for git commit messages, which is:
> 
>   1. more comprehensive in splitting up the various
>      components of the file
> 
>   2. in accordance with the usual vim behavior for syntax
>      highlighting (e.g., respecting b:current_syntax)
> 
>   3. presumably better maintained (I have not been using
>      what's in git's contrib/ directory for some time in
>      favor of the upstream version)
> 
> Furthermore, vim 7.2 also provides syntax highlighting for
> other git filetypes (gitconfig, rebase, send-email).
> 
> This patch gets rid of our local version and just points
> interested parties to the upstream version.
> 
> The code for auto-detecting filetypes is taken from vim 7.2's
> runtime/filetype.vim.
> 
> ---
>  contrib/vim/README               |   38 ++++++++++++++++++++++++++++++--------
>  contrib/vim/syntax/gitcommit.vim |   18 ------------------
>  2 files changed, 30 insertions(+), 26 deletions(-)
>  delete mode 100644 contrib/vim/syntax/gitcommit.vim
Missing SBO line?
 
-- 
Shawn.
SZEDER Gábor· Sep 29, 2008, 20:08 UTC · re: Shawn O. Pearce · lore

[PATCH] remove vim syntax highlighting in favor of upstream

As of version 7.2, vim ships with its own syntax highlighting for git commit messages, which is:

  1. more comprehensive in splitting up the various
     components of the file
  2. in accordance with the usual vim behavior for syntax
     highlighting (e.g., respecting b:current_syntax)
  3. presumably better maintained (I have not been using
     what's in git's contrib/ directory for some time in
     favor of the upstream version)

Furthermore, vim upsream also provides syntax highlighting for other git filetypes (gitconfig, rebase, send-email).

This patch gets rid of our local version and just points interested parties to the upstream version.

The code for auto-detecting filetypes is taken from vim's runtime/filetype.vim.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
On Mon, Sep 29, 2008 at 07:55:42AM -0700, Shawn O. Pearce wrote:
> Missing SBO line?

Here it is. Since significant parts of the patch and the commit message are from Jeff, maybe he should sign off, too?

Note, that this patch is slightly different from the previous one, as it proposes writing the auto-detect commands into ~/.vim/filetype.vim instead of ~/.vimrc. It's not quite clear to me why, but it seems to resolve the filetype confusion I mentioned in my previous email.

 contrib/vim/README               |   38 ++++++++++++++++++++++++++++++--------
 contrib/vim/syntax/gitcommit.vim |   18 ------------------
 2 files changed, 30 insertions(+), 26 deletions(-)
 delete mode 100644 contrib/vim/syntax/gitcommit.vim
Show changes to 2 files +30 −26

contrib/vim/README, contrib/vim/syntax/gitcommit.vim

diff --git a/contrib/vim/README b/contrib/vim/README
index 9e7881f..c487346 100644
--- a/contrib/vim/README
+++ b/contrib/vim/README
@@ -1,8 +1,30 @@
-To syntax highlight git's commit messages, you need to:
-  1. Copy syntax/gitcommit.vim to vim's syntax directory:
-     $ mkdir -p $HOME/.vim/syntax
-     $ cp syntax/gitcommit.vim $HOME/.vim/syntax
-  2. Auto-detect the editing of git commit files:
-     $ cat >>$HOME/.vimrc <<'EOF'
-     autocmd BufNewFile,BufRead COMMIT_EDITMSG set filetype=gitcommit
-     EOF
+Syntax highlighting for git commit messages, config files, etc. is
+included with the vim distribution as of vim 7.2, and should work
+automatically.
+
+If you have an older version of vim, you can get the latest syntax
+files from the vim project:
+
+  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/git.vim
+  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/gitcommit.vim
+  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/gitconfig.vim
+  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/gitrebase.vim
+  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/gitsendemail.vim
+
+To install:
+
+  1. Copy these files to vim's syntax directory $HOME/.vim/syntax
+  2. To auto-detect the editing of various git-related filetypes:
+	$ cat >>$HOME/.vim/filetype.vim <<'EOF'
+	autocmd BufNewFile,BufRead *.git/COMMIT_EDITMSG    setf gitcommit
+	autocmd BufNewFile,BufRead *.git/config,.gitconfig setf gitconfig
+	autocmd BufNewFile,BufRead git-rebase-todo         setf gitrebase
+	autocmd BufNewFile,BufRead .msg.[0-9]*
+		\ if getline(1) =~ '^From.*# This line is ignored.$' |
+		\   setf gitsendemail |
+		\ endif
+	autocmd BufNewFile,BufRead *.git/**
+		\ if getline(1) =~ '^\x\{40\}\>\|^ref: ' |
+		\   setf git |
+		\ endif
+	EOF
diff --git a/contrib/vim/syntax/gitcommit.vim b/contrib/vim/syntax/gitcommit.vim
deleted file mode 100644
index 332121b..0000000
--- a/contrib/vim/syntax/gitcommit.vim
+++ /dev/null
@@ -1,18 +0,0 @@
-syn region gitLine start=/^#/ end=/$/
-syn region gitCommit start=/^# Changes to be committed:$/ end=/^#$/ contains=gitHead,gitCommitFile
-syn region gitHead contained start=/^#   (.*)/ end=/^#$/
-syn region gitChanged start=/^# Changed but not updated:/ end=/^#$/ contains=gitHead,gitChangedFile
-syn region gitUntracked start=/^# Untracked files:/ end=/^#$/ contains=gitHead,gitUntrackedFile
-
-syn match gitCommitFile contained /^#\t.*/hs=s+2
-syn match gitChangedFile contained /^#\t.*/hs=s+2
-syn match gitUntrackedFile contained /^#\t.*/hs=s+2
-
-hi def link gitLine Comment
-hi def link gitCommit Comment
-hi def link gitChanged Comment
-hi def link gitHead Comment
-hi def link gitUntracked Comment
-hi def link gitCommitFile Type
-hi def link gitChangedFile Constant
-hi def link gitUntrackedFile Constant
-- 
1.6.0.2.330.gcef5c
Jeff King· Sep 29, 2008, 20:12 UTC · re: SZEDER Gábor · lore

Re: [PATCH] remove vim syntax highlighting in favor of upstream

On Mon, Sep 29, 2008 at 10:08:14PM +0200, SZEDER Gábor wrote:
> Here it is.  Since significant parts of the patch and the commit
> message are from Jeff, maybe he should sign off, too?

I think all of my changes were deletions, so I'm not sure there is any copyright to claim. ;) But:

Signed-off-by: Jeff King <peff@peff.net>
> Note, that this patch is slightly different from the previous one, as
> it proposes writing the auto-detect commands into ~/.vim/filetype.vim
> instead of ~/.vimrc.  It's not quite clear to me why, but it seems to
> resolve the filetype confusion I mentioned in my previous email.

I haven't really tested this at all, as I have been running vim 7.2 for a while now. But presumably it works for you, and hey, it's only contrib/. :)

-Peff
Michael J Gruber· Sep 30, 2008, 08:29 UTC · re: SZEDER Gábor · lore

Re: [PATCH] remove vim syntax highlighting in favor of upstream

SZEDER Gábor venit, vidit, dixit 29.09.2008 22:08:
Show 84 quoted lines
> As of version 7.2, vim ships with its own syntax
> highlighting for git commit messages, which is:
> 
>   1. more comprehensive in splitting up the various
>      components of the file
> 
>   2. in accordance with the usual vim behavior for syntax
>      highlighting (e.g., respecting b:current_syntax)
> 
>   3. presumably better maintained (I have not been using
>      what's in git's contrib/ directory for some time in
>      favor of the upstream version)
> 
> Furthermore, vim upsream also provides syntax highlighting
> for other git filetypes (gitconfig, rebase, send-email).
> 
> This patch gets rid of our local version and just points
> interested parties to the upstream version.
> 
> The code for auto-detecting filetypes is taken from vim's
> runtime/filetype.vim.
> 
> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
> ---
> 
> On Mon, Sep 29, 2008 at 07:55:42AM -0700, Shawn O. Pearce wrote:
>> Missing SBO line?
> Here it is.  Since significant parts of the patch and the commit
> message are from Jeff, maybe he should sign off, too?
> 
> Note, that this patch is slightly different from the previous one, as
> it proposes writing the auto-detect commands into ~/.vim/filetype.vim
> instead of ~/.vimrc.  It's not quite clear to me why, but it seems to
> resolve the filetype confusion I mentioned in my previous email.
> 
> 
>  contrib/vim/README               |   38 ++++++++++++++++++++++++++++++--------
>  contrib/vim/syntax/gitcommit.vim |   18 ------------------
>  2 files changed, 30 insertions(+), 26 deletions(-)
>  delete mode 100644 contrib/vim/syntax/gitcommit.vim
> 
> diff --git a/contrib/vim/README b/contrib/vim/README
> index 9e7881f..c487346 100644
> --- a/contrib/vim/README
> +++ b/contrib/vim/README
> @@ -1,8 +1,30 @@
> -To syntax highlight git's commit messages, you need to:
> -  1. Copy syntax/gitcommit.vim to vim's syntax directory:
> -     $ mkdir -p $HOME/.vim/syntax
> -     $ cp syntax/gitcommit.vim $HOME/.vim/syntax
> -  2. Auto-detect the editing of git commit files:
> -     $ cat >>$HOME/.vimrc <<'EOF'
> -     autocmd BufNewFile,BufRead COMMIT_EDITMSG set filetype=gitcommit
> -     EOF
> +Syntax highlighting for git commit messages, config files, etc. is
> +included with the vim distribution as of vim 7.2, and should work
> +automatically.
> +
> +If you have an older version of vim, you can get the latest syntax
> +files from the vim project:
> +
> +  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/git.vim
> +  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/gitcommit.vim
> +  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/gitconfig.vim
> +  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/gitrebase.vim
> +  http://vim.svn.sourceforge.net/viewvc/vim/trunk/runtime/syntax/gitsendemail.vim
> +
> +To install:
> +
> +  1. Copy these files to vim's syntax directory $HOME/.vim/syntax
> +  2. To auto-detect the editing of various git-related filetypes:
> +	$ cat >>$HOME/.vim/filetype.vim <<'EOF'
> +	autocmd BufNewFile,BufRead *.git/COMMIT_EDITMSG    setf gitcommit
> +	autocmd BufNewFile,BufRead *.git/config,.gitconfig setf gitconfig
> +	autocmd BufNewFile,BufRead git-rebase-todo         setf gitrebase
> +	autocmd BufNewFile,BufRead .msg.[0-9]*
> +		\ if getline(1) =~ '^From.*# This line is ignored.$' |
> +		\   setf gitsendemail |
> +		\ endif
> +	autocmd BufNewFile,BufRead *.git/**
> +		\ if getline(1) =~ '^\x\{40\}\>\|^ref: ' |
> +		\   setf git |
> +		\ endif
> +	EOF
Works as described with vim 7.1.

How about creating a syntax file for editing the files generated by format-patch, especially 0000-cover-letter.patch? Should be mostly a combination of "git.vim" and "gitsendemail.vim", but I didn't find any syntax defs for the diffstat.

Michael

P.S.: What? Git doc linking to an svn repo? Someone needs to set up a git mirror ;)

← back to recent threads