2

A bit of context: I'm trying to use NeoVim after Spacemacs. In Spacemacs, there is gql key combination that hard wraps current long line of text into multiple short lines. It is useful if I want to write a long documentation comment. So I write a single line and let the IDE figure out linebreaks.

When I'm trying to configure NeoVim to wrap lines. And I want to achieve the following behaviour:

  1. Don't wrap lines automatically when reaching a specific limit (like 80 columns).
  2. Wrap line (ideally preserving indentation) with some hotkey like gql.

I tried :set tw=80 and I can wrap lines by gqq, but they are also wrapped automatically...

How can I configure my NeoVim environment to do this?

1
:set fo-=tc

You can set 'formatoptions' with your preferences controlling when and how to format text.

See :help fo-table for the list of supported values in this option.

In particular, you'll want to remove these two:

t: Auto-wrap text using 'textwidth'

c: Auto-wrap comments using 'textwidth', inserting the current comment leader automatically.

So, to remove them:

set formatoptions-=tc

Or the short abbreviated form at the beginning of the answer.

You'll probably want to make sure you're preserving this one, applicable to comments specifically:

q: Allow formatting of comments with gq.

It's typically included in the default (which is tcq), so usually you don't need any action to keep it.

See also:

  • The 'comments' option.
  • The full fo-table for more useful options related to formatting and breaking lines.

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.