Vim has the excellent command set tw=79
which will automatically break your lines at 79 characters, however I like (just) my comments broken at 72 characters automatically.
Is there any good way to do this in Vim?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityI like this one
augroup comment_textwidth
autocmd!
autocmd TextChanged,TextChangedI * :call AdjustTextWidth()
augroup END
function! AdjustTextWidth()
let syn_element = synIDattr(synID(line("."), col(".") - 1, 1), "name")
let &textwidth = syn_element =~? 'comment' ? 72 : 79
echo "tw = " . &textwidth
endfunction
For more inspiration look here.