Making vim show a git diff with colors like a git diff command (red-delete, green-add) -


i ran git config --global alias.ci commit --verbose

this makes running git ci running git commit --verbose

the --verbose flag shows diff in commit message template, not commented syntax highlighting works on it, automatically recognized not submitted repository's log. can, of course, long, can useful creating better commit comments. (and, if don't need it, can ignore it.)

anyways, if run git diff, lines removed (start '-') in red, , lines added (start '+') in green.

if run git ci, vim syntax highlights lines removed regular color (white), , lines added cyan.

how can make vim syntax highlight show removed lines in red , addes ones in green?

the vim status line says it's editing file "~/code.git/.git/commit_editmsg". don't know vim syntax highlighting, know it's configurable. i'm not sure how situation configurable, because assume vim uses file extensions in deciding syntax highlighting rules follow (i way off here) , git isn't giving file extension.

edit: actually, vim must detecting git commit file, because it's syntax highlighting first 50 characters yellow. assuming that's indicate can nicely fit on emailed subject line patch.

the short version: edit file ~/.vim/after/syntax/gitcommit.vim, , add this:

hi diffadded   ctermfg=green hi diffremoved ctermfg=red 

the longer version, explaining how got there:

when edit commit message, run :set ft. show git commit files have filetype gitcommit. consequently, modify highlighting commit messages need edit file syntax/gitcommit.vim, , since want changes override normal highlighting, need put in after/ directory. ~/.vim/after/syntax/gitcommit.vim.

now, find out change. there tremendously useful piece of code, picked somewhere (from tpope, iirc), , have been using happily ever after:

nmap <c-s-p> :call <sid>synstack()<cr> function! <sid>synstack()   if !exists("*synstack")     return   endif      echo map(synstack(line('.'), col('.')), 'synidattr(v:val, "name")') endfunc 

with this, open verbose commit, go removed chunk, , press ctrl-shift-p. show ['gitcommitdiff', 'diffremoved']. go added chunk, , ['gitcommitdiff', 'diffadded'].

looking @ /usr/share/vim/vim74/syntax/gitcommit.vim shows what's going on: syntax/gitcommit.vim includes syntax/diff.vim, standard highlighting file diff. patterns above.

looking @ end of /usr/share/vim/vim74/syntax/diff.vim, you'll find other patterns might need change.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -