2

I know the breakindent option works with linebreak to preserve indent on wrapped lines. However, when I want to hard wrap lines (using the textwidth option so <EOL> is inserted when a line reaches the length specified by textwidth), breakindent has no effect (e.g. the new line created has no indentation). I assume breakindent is not intended to work with textwidth the way I was expecting. Is there an existing solution to this, or do I have to write a vimscript function to do what I want?

1

The 'autoindent' option enables this behavior:

When autoindent is on, formatting (with the gq command or when you reach 'textwidth' in Insert mode) uses the indentation of the first line.

Note that this option has interactions with other options such as 'smartindent' and 'cindent'. Also, if an 'indentexpr' is set, it can often override what 'autoindent' does. An 'indentexpr' is often set if you have filetype indent on, so watch out for those.

But in general, this should be enough:

set autoindent
  • 1
    Many thanks. Don't know how I didn't find this earlier. – myc3lium Feb 2 at 18:43

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.