5

Having vim setup for development gives some undesirable effects for editing commit messages (margin not 72, auto-indent typically isn't needed, probably literal tab characters aren't desired, maybe strip trailing space on save?... etc).

What are good filetype options for git commit messages?

function MyFTypeGitCommit()
  " Good options for commit messages.
endfunc

autocmd FileType gitcommit call MyFTypeGitCommit()

Note, I could post my settings but not sure they're worth promoting for others to use, if someone has this figured out it's likely going to be a more useful answer.

2 Answers 2

4

Posting own answer, in case others find it useful.

function MyFTypeGitCommit()
  " Check spelling.
  setlocal spell
  " Make bad spelling very obvious! (personal preference).
  :hi SpellBad ctermbg=red ctermfg=white guibg=red guifg=white

  " Never auto-indent.
  setlocal indentexpr=''

  " No literal tabs, indent 4.
  setlocal expandtab shiftwidth=4 tabstop=4

  " Margin for emails, make it obvious where 72 characters is.
  setlocal textwidth=72
  setlocal colorcolumn=+1

  " Strip space on save.
  fun! <SID>StripTrailingWhitespaces()
    let l = line(".")
    let c = col(".")
    %s/\s\+$//e
    call cursor(l, c)
  endfun
  autocmd BufWritePre <buffer> :call <SID>StripTrailingWhitespaces()
endfun

autocmd FileType gitcommit call MyFTypeGitCommit()
3

I am using this in ftplugin/gitcommit.vim:

" Enable spellchecking
if has('spell')
  setlocal spell
endif

" Automatically wrap at 72 characters
setlocal textwidth=72

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.