top | item 5326125

Vim Git Gutter

371 points| glazskunrukitis | 13 years ago |github.com | reply

115 comments

order
[+] jaytaylor|13 years ago|reply
This is really nice, but I wish the background color of the gutter would automatically match the rest of my background. The gray band [1] is pretty unappealing IMO.

Also noteworthy is that that the gutter only updates when the file is saved.

[1] Screenshot: http://imgur.com/TIGKVRS

[+] airblade|13 years ago|reply
You can achieve that manually with `highlight clear SignColumn` in your colour scheme or ~/.vimrc.

I'll (I'm the author) probably make this the default because it seems quite a common wish.

[+] graywh|13 years ago|reply
What colorscheme? Is it just not changing the default colors for the SignColumn group?
[+] shuzchen|13 years ago|reply
I've also got a similar plugin https://bitbucket.org/sirpengi/iwilldiffer that works with hg as well as git. Mine uses python though, nice to see an implementation that's all in viml. Neither of our plugins are async though (so vim ui will block while the diff is running), which is the biggest hurdle I want to cross.
[+] airblade|13 years ago|reply
As far as I know Vim is single-threaded; you can't run operations asynchronously.
[+] morsch|13 years ago|reply
Eclipse pretty much does this out of the box. I guess so do IntelliJ and Visual Studio. You can also display the name of the last person to change a line in the same position (ie. svn/git blame), which is very useful to quickly find out who to talk to regarding a section of a file. The commit message is displayed on mouseover.
[+] msluyter|13 years ago|reply
Yes, IntelliJ handles this pretty nicely. For modified lines, you can mouse over to see what you changed. For all changes, you can click a context menu to revert any given change. (Of course, that does require touching a mouse... though I believe you can set up a key mapping for it.)
[+] amadeus|13 years ago|reply
Using the vim Fugitive you can quickly toggle a git blame sidebar to determine all this similar type of information.
[+] cr4zy|13 years ago|reply
Also gotta love the ability to open commits in Github in IntelliJ and the other JetBrains IDE's. Great for sending a link to a line of code.
[+] ylaassel|13 years ago|reply
It'd be perfect if the signs changed in real-time without the need to save first. Awesome work though. Thanks Andy.
[+] airblade|13 years ago|reply
I'll look into that...
[+] soupboy|13 years ago|reply
+1 that request. Really good plugin otherwise.
[+] bryanallen22|13 years ago|reply
Taglist does something similar, and it uses ':h updatetime' to toggle how often it works.
[+] krallin|13 years ago|reply
My thoughts exactly, that would be awesome!
[+] swah|13 years ago|reply
That's a lot of "git diff" calls!
[+] ianbishop|13 years ago|reply
Is there any way to make it so that the gutter is always present? There's a bit of a noticeable jump to include it when I save a file, it's sort of annoying me.

I tried

  let g:gitgutter_enabled = 1
but that does seem to work.

I'll have a poke through the source.

[+] shuzchen|13 years ago|reply
probably not, the way vim works if there are no more signs attached to a document the gutter goes away. This isn't plugin related, it's just a manner of how vim works.

Although I suppose you can work around this by displaying a fake sign (color match gutter background?), but that has its downsides (depending on colorscheme, the sign can show up. and vim doesn't support whitespace characters for signs, at least not from what I can see).

[+] lloeki|13 years ago|reply
I wish it could be made to stand on the right side of a vim buffer. This way it would still be present on demand but would not shift the whole buffer one column to the right.
[+] jisaacks|13 years ago|reply
Ugh, someone submitted the original Sublime version to hackers news 2 months go http://news.ycombinator.com/item?id=5027308 and it got no love.

It just makes sense that someone would port it and become the #1 story.

[+] shuzchen|13 years ago|reply
Maybe because there are more vim users than sublime users on hn? FWIW i did see that story on front-page of hn and it's what prompted me to immediately write my vim-port. I finished it like a few days after that.
[+] kristopolous|13 years ago|reply
An aside question; what's the deal with "pathogen"?

I've been using the "/bin/cp" command for years installing vim plugins and it's worked remarkably well; requiring just about 1 invocation on average...

What problem does that thing solve?

[+] MBlume|13 years ago|reply
If you decide you no longer want a particular plugin, or want to upgrade it, it can be hard to tease out the files you /bin/cp'd into place. Adding a single folder under bundle makes removal easier later.

ETA: also note that git-cloning into bundle means that upgrading is just a question of entering the plugin directory and running git pull.

[+] agscala|13 years ago|reply
Each plugin resides in it's own directory, rather than being scattered around your .vim dir. Try to remove one of your installed plugins, you'll have to dig around and it'll be messy.

Also it makes it easier to update, since all you need to do is replace the folder with the newer version and you're all set.

[+] lftl|13 years ago|reply
To elaborate on the response others have offered about everything being in one folder, I'll further note that it allows you to keep track of the plugin through git, so you can very easily grab updates when desired.
[+] bostonvaulter2|13 years ago|reply
I have 5 separate computers that I run vim on. Manually installing and updating is a huge pain. I keep my .vimrc in git to keep them all synchronized.
[+] SeoxyS|13 years ago|reply
Three killer uses:

- removal - git submodules - conditional loading of plugins

[+] mercurial|13 years ago|reply
It lets you put your various vim things inside a single 'bundle' directory instead of having files in plugin/ftplugin and whatnot. Very convenient and easy to setup.
[+] finnh|13 years ago|reply
Seems to add noticeable latency (1+ seconds) to my save, each time. Vim is unresponsive during this time

Is this expected? I save quite frequently, it's an unconscious reflex at this point.

[+] jaytaylor|13 years ago|reply
Out of curiosity, what is the line count on the file where this is happening?
[+] jayroh|13 years ago|reply
This works really quite well - great work, airblade! For reference, this is what I placed in my vimrc to get things how I like them:

  highlight clear signcolumn
  let g:gitgutter_enabled = 0
  nmap <leader>gu :GitGutterToggle<CR>

I prefer my buffers to start with it disabled by default and toggle as needed.
[+] prg318|13 years ago|reply
I'm really impressed with this -- I would love to see this see functionality for other VCSes (subversion, etc) so that I could use it with my non-git projects. The vimscript looks pretty clean -- maybe I have a new weekend project ahead of me.

edit: just a quick hack for a "vim svn gutter": https://github.com/prg318/vim-gitgutter

The code is really clean and it would be fairly trivial to adopt this for use with any other VCS. Open source yay!

[+] methodin|13 years ago|reply
Any way to bind "toggle the gutter" so I can press my "set nonumber" button and have it toggle the gutter as well? [edit] Apparently I didn't read down far enough! This functionality exists already through the plugin. This works for me: nnoremap <F2> :set nonumber! <bar> ToggleGitGutter<CR>
[+] swift|13 years ago|reply
vim-patchreview is a bit different, but also of interest: https://github.com/vim-scripts/patchreview.vim

I find it really useful in particular for working with Mercurial patch queues. I have a command in my .vimrc that will run ReversePatchReview on the topmost patch in my patch queue. It pops up a diff tab for each file that has changed. I can easily use "[c" and "]c" to jump between changes within each file.

This setup makes it incredibly easy to review the changes a patch makes, and it's so convenient that I often write quite a bit of my code inside these diff views. I don't think I could live without vim-patchreview when working with Mercurial.

[+] bilalq|13 years ago|reply
This looks amazing. Nice work! Does it always diff with the last commit?
[+] airblade|13 years ago|reply
It diffs your working tree with the index (i.e. what a plain git-diff does). I plan to make it easy to `git-diff --cached` too.
[+] purephase|13 years ago|reply
Very cool. Pointed me at the Sublime Text version and I love it.
[+] awef|13 years ago|reply
Awesome work! Cheers airblade. One nitpicky thing though, why do you use "_" and not "-" for removed lines? Can't see why you wouldn't want it vertically centered!
[+] marcamillion|13 years ago|reply
I would love something like this for TextMate 2.