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 Answer
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