5

With at least these settings:

expandtab
textwidth=79
sw=4
ts=4
fo=tcq

If I have a long line of text that starts with a * (like a C/javadoc comment) it will honor the current indent level when I gqq, albeit formatting it like a code comment, e.g.:

* I'm convinced of this: Good done anywhere is good done everywhere...

=>

* I'm convinced of this: Good done anywhere is good done
* everywhere. For a change, start by speaking to people
* rather than walking by them like they're stones that
* don't matter. As long as you're breathing, it's never too
* late to do some good.

However, if I remove the leading *, it just wraps flush with the left:

    I'm convinced of this: Good done anywhere is good done
everywhere. For a change, start by speaking to people rather than walking by
them like they're stones that don't matter. As long as you're breathing, it's
never too late to do some good.

I'm just doing plain text prose in a .txt. How can I make it look like the following, ideally without any fancy leading char?

I'm convinced of this: Good done anywhere is good done
everywhere. For a change, start by speaking to people rather
than walking by them like they're stones that don't matter.
As long as you're breathing, it's never too late to do some
good.

I was able to do this by manually deleting all leading whitespace, passing the line through :!fmt -w60, and then block inserting 20 spaces; but that involves a lot of math and typing, a cumbersome external command, and is not platform independent (wouldn't work in windows, for instance).

Sample Text is a quote from Maya Angelou.

2

It looks like if you have autoindent set, then gqq honors the indentation of the line you’re on.

Here is my setup:

    ~ ω  vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Feb 10 2016 14:15:10)
MacOS X (unix) version
Included patches: 1-1257
Compiled by Homebrew
...

Start Vim without any initialization files:

vim -u NONE

Then:

  • paste in a long line and giving it any indent
  • :set autoindent
  • gqq

Give it a try! 8-)

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.