8

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?

9

I 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

Source

For more inspiration look here.

  • 1
    Funny thing is, I never thought of that solution as a serious one :) – VanLaser Sep 22 '15 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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