My Vim configuration includes set formatoptions=c,q,a. I am completely annoyed with the following problem (| denotes cursor position, its exact position does not matter, as you probably know only the fact of its presence in this commented line matters):
" This is a long line which we would like to wrap. However, something sick is go|ing to happen if we hit "gqip" here!
if has('win32') || has('win64')
set runtimepath^=~/.vim
set runtimepath+=~/.vim/after
endif
Now we hit gqip:
" This is a long line which we would like to wrap. However, something sick is
" go|ing to happen if we hit "gqip" here!
if has('win32') || has('win64') set runtimepath^=~/.vim set
runtimepath+=~/.vim/after endif
What it does is – it actually treats the whole thing as a single paragraph. (Yes, I know that separating with a blank line prevents this behavior, but it does not solve the problem!) What I would like it to be is indeed:
" This is a long line which we would like to wrap. However, something sick is
" go|ing to happen if we hit "gqip" here!
if has('win32') || has('win64')
set runtimepath^=~/.vim
set runtimepath+=~/.vim/after
endif
In other words, it would be great if gq could somehow forget about the code and work only with comments.
BONUS: How to do this formatting (wrapping comments only) on the whole buffer in one shot? Because, ideally I would like to move that stuff to a special formatting hook for file saving.
With my SameSyntaxMotion plugin, you can use the
aytext object to represent the entire block of comments the cursor is in, and re-format it usinggqay.