Committing every time you save in Vim

I wonder if there are any non squash-heavy workflows that this goes well with.

" requires vim-python and python-git
function! CommitFile()
python << EOF
import vim, git
curfile = vim.current.buffer.name
if curfile:
    try:
        repo = git.Repo(curfile)
        repo.git.add(curfile)
        repo.git.commit(m='Update')
    except (git.InvalidGitRepositoryError, git.GitCommandError):
        pass
EOF
endfunction
au BufWritePost * call CommitFile()

Comments (4)

nion

terrible feature but nice poc! :)

Feb. 3, 2009, 10:11 p.m. #
Sam Williams

I wouldn't say terrible feature necessarily. Bad work-flow idea for normal code development though. If you are going to use it for writing this is might be a different story. Cory Doctorow just had a python based tool created for a writers work-flow called FlashBake, in case you are interested.

Feb. 16, 2009, 11:25 p.m. #

Hi!

Neat hack. I found out it makes sense to use, for my latex files!

So this is what I hacked up for editing LaTeX files, with a bit of help from vim gurus from #vim.

1. Use git's gitattribute *.tex diff=tex to get nice hunk headers
2. Tweak the script to put in the first hunk header in the commit message, that way the log tells me where I changed something
3. Use a "dotted filetype" (thanks vim gurus) to enable this. I have an autocommand trigger on FileType *.autocommit, so for the files where I want this I define "set ft=tex.autocommit"

.vimrc code here:

http://gist.gi…

March 7, 2009, 10:22 p.m. #

Thanks!

This helped me to get my Taglist updated everytime I save the current buffer.

autocmd BufWritePost * :TlistUpdate

Feb. 17, 2010, 5:15 p.m. #