# [PATCH] contrib/vim: add syntax highlighting file for commits

6 messages from 2006-09-11 to 2006-09-13. Participants: Jeff King, Tom Prince, Junio C Hamano.
Thread: https://gitlist.dev/t/5539

## Jeff King, 2006-09-11 23:22

Subject: [PATCH] contrib/vim: add syntax highlighting file for commits
Message-ID: <20060911232249.GB29736@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20060911232249.GB29736%40coredump.intra.peff.net

```

Signed-off-by: Jeff King <peff@peff.net>
---
There were at least a few positive comments on this, and hey, we have to
balance the contrib/emacs directory!

 contrib/vim/README            |    7 +++++++
 contrib/vim/commit-syntax.vim |   18 ++++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/contrib/vim/README b/contrib/vim/README
new file mode 100644
index 0000000..bad0a05
--- /dev/null
+++ b/contrib/vim/README
@@ -0,0 +1,7 @@
+To syntax highlight git's commit messages, you need to:
+  1. Copy commit-syntax.vim to vim's syntax directory:
+     $ cp commit-syntax.vim $HOME/.vim/syntax/gitcommit.vim
+  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/commit-syntax.vim b/contrib/vim/commit-syntax.vim
new file mode 100644
index 0000000..a9de09f
--- /dev/null
+++ b/contrib/vim/commit-syntax.vim
@@ -0,0 +1,18 @@
+syn region gitLine start=/^#/ end=/$/
+syn region gitCommit start=/^# Updated but not checked in:$/ 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.4.2.g39f1

```

## Tom Prince, 2006-09-12 02:08

Subject: Re: [PATCH] contrib/vim: add syntax highlighting file for commits
Message-ID: <20060912020813.GD26332@socrates.priv>
URL: https://gitlist.dev/e/20060912020813.GD26332%40socrates.priv
In-Reply-To: <20060911232249.GB29736@coredump.intra.peff.net>

```
On Mon, Sep 11, 2006 at 07:22:49PM -0400, Jeff King wrote:
> +  1. Copy commit-syntax.vim to vim's syntax directory:
> +     $ cp commit-syntax.vim $HOME/.vim/syntax/gitcommit.vim
...
> diff --git a/contrib/vim/commit-syntax.vim b/contrib/vim/commit-syntax.vim

It would be more obvious if you could do cp gitcomit.vim $HOME/.vim/syntax/

  Tom

```

## Jeff King, 2006-09-12 02:32

Subject: Re: [PATCH] contrib/vim: add syntax highlighting file for commits
Message-ID: <20060912023256.GA6596@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20060912023256.GA6596%40coredump.intra.peff.net
In-Reply-To: <20060912020813.GD26332@socrates.priv>

```
On Mon, Sep 11, 2006 at 08:08:13PM -0600, Tom Prince wrote:

> > +  1. Copy commit-syntax.vim to vim's syntax directory:
> > +     $ cp commit-syntax.vim $HOME/.vim/syntax/gitcommit.vim
> It would be more obvious if you could do cp gitcomit.vim $HOME/.vim/syntax/

It would be with only one file, but you could just as easily have a
.vim/ftplugin/gitcommit.vim file (I think there are others, too). If you
want to give it the "proper" name, it should probably be
syntax/gitcommit.vim.

-Peff

```

## Junio C Hamano, 2006-09-13 06:12

Subject: Re: [PATCH] contrib/vim: add syntax highlighting file for commits
Message-ID: <7vy7so9txj.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vy7so9txj.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20060912023256.GA6596@coredump.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> On Mon, Sep 11, 2006 at 08:08:13PM -0600, Tom Prince wrote:
>
>> > +  1. Copy commit-syntax.vim to vim's syntax directory:
>> > +     $ cp commit-syntax.vim $HOME/.vim/syntax/gitcommit.vim
>> It would be more obvious if you could do cp gitcomit.vim $HOME/.vim/syntax/
>
> It would be with only one file, but you could just as easily have a
> .vim/ftplugin/gitcommit.vim file (I think there are others, too). If you
> want to give it the "proper" name, it should probably be
> syntax/gitcommit.vim.

I am not a vim user, but my reading of Tom's comment is that he
thinks it would have been nicer if the file the patch adds were
named gitcommit.vim, not commit-syntax.vim.  As you seem to
agree that the preferred name for this file when deployed is
gitcommit.vim, how about something like this on top of your
patch perhaps?


diff --git a/contrib/vim/README b/contrib/vim/README
index bad0a05..f574cc8 100644
--- a/contrib/vim/README
+++ b/contrib/vim/README
@@ -1,6 +1,6 @@
 To syntax highlight git's commit messages, you need to:
-  1. Copy commit-syntax.vim to vim's syntax directory:
-     $ cp commit-syntax.vim $HOME/.vim/syntax/gitcommit.vim
+  1. Copy gitcommit.vim to vim's syntax directory:
+     $ cp 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
diff --git a/contrib/vim/commit-syntax.vim b/contrib/vim/gitcommit.vim
similarity index 100%
rename from contrib/vim/commit-syntax.vim
rename to contrib/vim/gitcommit.vim

```

## Jeff King, 2006-09-13 06:25

Subject: Re: [PATCH] contrib/vim: add syntax highlighting file for commits
Message-ID: <20060913062557.GA4783@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20060913062557.GA4783%40coredump.intra.peff.net
In-Reply-To: <7vy7so9txj.fsf@assigned-by-dhcp.cox.net>

```
On Tue, Sep 12, 2006 at 11:12:08PM -0700, Junio C Hamano wrote:

> I am not a vim user, but my reading of Tom's comment is that he
> thinks it would have been nicer if the file the patch adds were
> named gitcommit.vim, not commit-syntax.vim.  As you seem to
> agree that the preferred name for this file when deployed is
> gitcommit.vim, how about something like this on top of your
> patch perhaps?

My point was that there may be many files named gitcommit.vim; the
directory they appear in under your .vim directory has significance. If
we add another such file, they will conflict in the flattened namespace
of contrib/vim.  See below (which also adds the necessary mkdir
command):

-- >8 --
contrib/vim: give commit-syntax a more sensible name

diff --git a/contrib/vim/README b/contrib/vim/README
index bad0a05..9e7881f 100644
--- a/contrib/vim/README
+++ b/contrib/vim/README
@@ -1,6 +1,7 @@
 To syntax highlight git's commit messages, you need to:
-  1. Copy commit-syntax.vim to vim's syntax directory:
-     $ cp commit-syntax.vim $HOME/.vim/syntax/gitcommit.vim
+  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
diff --git a/contrib/vim/commit-syntax.vim b/contrib/vim/syntax/gitcommit.vim
similarity index 100%
rename from contrib/vim/commit-syntax.vim
rename to contrib/vim/syntax/gitcommit.vim

```

## Tom Prince, 2006-09-13 06:46

Subject: Re: [PATCH] contrib/vim: add syntax highlighting file for commits
Message-ID: <20060913064640.GA3731@socrates.priv>
URL: https://gitlist.dev/e/20060913064640.GA3731%40socrates.priv
In-Reply-To: <20060913062557.GA4783@coredump.intra.peff.net>

```
On Wed, Sep 13, 2006 at 02:25:57AM -0400, Jeff King wrote:
 
> My point was that there may be many files named gitcommit.vim; the
> directory they appear in under your .vim directory has significance. If
> we add another such file, they will conflict in the flattened namespace
> of contrib/vim.  See below (which also adds the necessary mkdir
> command):
> 

Much clearer. I had glanced at the readme and did
cp commit-syntax.vim ~/.vim/syntax
and it took me a minute or so to figure what was wrong.

  Tom

```
