Vim Tips Wiki
Tip 1636 Printable Monobook Previous Next

created 2009 · complexity basic · author Khym Chanur · version 7.0

When editing a git commit message (.git/COMMIT_EDITMSG) you often won't start on the first line due to Vim remembering your last position in that file. An easy way to fix this is to add the following line to your vimrc:

autocmd FileType gitcommit call setpos('.', [0, 1, 1, 0])

Alternatively, you can create a file named gitcommit.vim in ~/.vim/ftplugin containing the following line:

call setpos('.', [0, 1, 1, 0])


We have two other short git tips:

Why is this tip needed when it is so easy to type gg to go to the first line? JohnBeckett 05:01, May 15, 2010 (UTC)

Probably because muscle-memory might lead someone to immediately try to insert text, without looking? ~Anon, 2012-08-21 8:47-0700

Also, you should hook other event, because FileType is too early, and cursor position will be overwritten using info from .viminfo:

function MyBufEnter()
  " don't (re)store filepos for git commit message files
  if &filetype == "gitcommit"
    call setpos('.', [0, 1, 1, 0])
au BufEnter * call MyBufEnter()

or just:

au FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0])