Is it possible to set textwidth based on whether the cursor is in code or comments?

106 views Asked by At

I'd like to make my comments 80 characters wide while allowing my code to go to 132 characters.

Is there a way to do this? I was looking at synID, but my viml-fu is not up to the task. I'm not even sure where to start.

1

There are 1 answers

0
Ingo Karkat On BEST ANSWER

My OnSyntaxChange plugin allows to define hooks based on the syntax under the cursor. This will do what you want:

call OnSyntaxChange#Install('Comment', '^Comment$', 0, 'a')
autocmd User SyntaxCommentEnterA setlocal textwidth=80
autocmd User SyntaxCommentLeaveA setlocal textwidth=132