From 52a738b89278e15a4d22418c68e4a142d849bca3 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 14 Jul 2018 23:51:34 +1200 Subject: Adaptive 'colorcolumn' for gitcommit filetype --- vim/after/ftplugin/gitcommit.vim | 10 ++++++++++ vim/autoload/gitcommit.vim | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 vim/autoload/gitcommit.vim (limited to 'vim') diff --git a/vim/after/ftplugin/gitcommit.vim b/vim/after/ftplugin/gitcommit.vim index 4f57a407..d390fa3c 100644 --- a/vim/after/ftplugin/gitcommit.vim +++ b/vim/after/ftplugin/gitcommit.vim @@ -8,6 +8,16 @@ setlocal comments+=n:> setlocal formatoptions+=coqr let b:undo_ftplugin .= '|setlocal comments< formatoptions<' +" Choose the color column depending on non-comment line count +if exists('+cursorcolumn') + augroup gitcommit + autocmd CursorMoved,CursorMovedI + \ let &l:colorcolumn = gitcommit#CursorColumn() + augroup END + let b:undo_ftplugin .= '|autocmd! gitcommit' + \ . '|augroup! gitcommit' +endif + " Stop here if the user doesn't want ftplugin mappings if exists('g:no_plugin_maps') || exists('g:no_gitcommit_maps') finish diff --git a/vim/autoload/gitcommit.vim b/vim/autoload/gitcommit.vim new file mode 100644 index 00000000..56b35ba6 --- /dev/null +++ b/vim/autoload/gitcommit.vim @@ -0,0 +1,20 @@ +" Choose the color column depending on non-comment line count +function! gitcommit#CursorColumn() abort + + " Last line number + let l:ll = line('$') + + " If we can find a line after the first that isn't a comment, we're + " composing the message + if l:ll > 1 + for l:li in range(2, l:ll) + if getline(l:li) !~# '^\s*#' + return '+1' + endif + endfor + endif + + " Otherwise, we're still composing our subject + return '51' + +endfunction -- cgit v1.2.3