Chris Lamb

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()

Chris Lamb is a freelance software developer and the current Debian Project Leader. You can read other posts by me, see software I have written or read more about me. You can also follow me @lolamby.


Tags: Hacks

Planets: ALUG UWCS Debian WUGLUG

Tuesday 3rd February 2009


Four comments