5

Is there an option I can set in Vim and Neovim to force the gq motion to wrap text strictly at 80 characters, without addings hanging indents after lines that begin with common programming keywords such as for, while, and if?

For instance, let's say I use the motion gq) on the each of the following sentences in normal mode with textwidth set to 20 (I choose 20 characters here so the original sentences fit in SO's code boxes without overflowing; I normally wrap at 80 characters):

if i am correct, this text should wrap without a hanging indent

while i would like to wrap without a hanging indent, vim has other plans

for now, i have to avoid starting sentences with certain words

After rewrapping at 20 characters:

if i am correct,
    this text should
    wrap without a
    hanging indent

while i would like
    to wrap without
    a hanging
    indent, vim has
    other plans

for now, i have to
    avoid starting
    sentences with
    certain words

Based on both the Vim and Neovim documentation for gq, I would expect words like if and while to have no impact on text rewrapping.

Is there an option I can set to disable this behavior? And where is this behavior documented?

Notes for completeness:

  • My formatoptions option is tcqj.
  • My linebreak option is not set (but this issue occurs when it is set, also).
  • Both my formatexpr and formatprg options are empty.
  • I am using NVIM v0.12.0-dev-999+ge6e1e71abf.
4
  • This is probably related to settings such as autoindent or smartindent (I don't remember the exact names). Commented Nov 14 at 19:47
  • 1
    Nice examples :) Commented Nov 14 at 19:49
  • What's does :set filetype? say? Your formatoptions are probably set for some programming language while you're editing plain text. See :help 'formatoptions' and the linked :help fo-table. Commented Nov 15 at 7:17
  • 1
    For the above examples, :set filetype? says filetype=text. This also happens when filetype=markdown and filetype=plaintex. I had checked fo-table; none of the options appear directly connected to the issue I am facing (i.e., none of them directly mention certain keywords affecting wrapping behavior). Commented Nov 15 at 19:15

1 Answer 1

3

You probably have :help 'smartindent' set.

You can…

  • disable it with:

    :set nosmartindent
    
  • see where it was set with:

    :verbose set smartindent?
    
  • and remove it from your config, as it has generally been superseded by filetype-specific indent script. And it has never really been that smart to begin with.

Sign up to request clarification or add additional context in comments.

1 Comment

It seems that my issue was due to smartindent being enabled, and the problematic words belonging to cinwords. Disabling smartindent solved my problem.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.