How to configure Vim word wrap options vimrc
Use :set wrap
and :set textwidth=N
. For permanent effect add the wrap settings to the vim
start-up file .vimrc
set wrap
set textwidth=X
To apply the wrapping to an existing file, move to the start of the file (you can use gg
to do this). Then type gqG
to apply the re-formatting to the entire file.
Also setting a margin may be useful:
set wrapmargin=0
If you want hard wrapping, i.e. real reformatting of the text by inserting newline characters, the 'textwidth'
setting (as outlined in suspectus's answer) is the key. You need to reformat existing text, e.g. via the gq
command.
For soft wrapping, i.e. where long lines just appear to be broken in the editor window, :set wrap
will always fill the entire available window space; you cannot restrict that to take less. Either resize the Vim window, or add a padding buffer to the right that restricts the available space to the current window. For the latter, my LimitWindowSize plugin may be helpful.