How to ignore keywords when rewrapping text in Vim?
15:37 14 Nov 2025

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.
vim neovim