2

I am looking for an easy way to reflow blocks of comments (in GO). According to this post I should be able to just run gq on a block and it will reflow automatically, but this doesn't seem to work.

Here is some sample text:

// PrintStarredRepos tries to print tags of repo's that have been starred
// adaf da df a da fs daf e according to the "user" configuration setting that is read in from the
// config file.

And this is what the text looks like after I run gq on it.

// PrintStarredRepos tries to print tags of repo's that have been starred //
adaf da df a da fs daf e according to the "user" configuration setting that is
read in from the // config file.

Here are relevant settings in my vimrc based on details I found in another post.

  • textwidth=80
  • filetype plugin indent on
  • set ft? (filetype=go)
  • set comments? (comments=s1:/,mb:,ex:*/,://)

I can't figure out why comments aren't wrapping?

2 Answers 2

8

In my vimrc file I had set paste turned on.

When I removed this configuration I was able to get comments to flow correctly.

1
  • 1
    If you set paste often (a very useful feature), don't forget to undo this with set nopaste once you have finished pasting. set paste, I've noticed, introduces some surprising side effects. Jun 16, 2018 at 16:20
4

You need to check your formatoptions setting. According to the manual you need the "q" flag to be present:

                                                        *fo-table*
You can use the 'formatoptions' option  to influence how Vim formats text.
'formatoptions' is a string that can contain any of the letters below.  The
default setting is "tcq".  You can separate the option letters with commas for
readability.

letter   meaning when present in 'formatoptions'
[...]
q   Allow formatting of comments with "gq".
    Note that formatting will not change blank lines or lines containing
    only the comment leader.  A new paragraph starts after such a line,
    or when the comment leader changes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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