- 0 Talk
-
Always start on first line of git commit message
Tip 1636 Printable Monobook Previous Next
created October 24, 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])
Comments
Edit
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)
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])
endif
endfunction
au BufEnter * call MyBufEnter()
cubuanic 2010/03/11