I'm trying to configure Vim so that it always wraps at x-number of columns automatically, at all times such as in this other editor that I provided a screenshot of-
Command to toggle word wrap in Vim While :set wrap will turn on word wrap in Vim and :set nowrap will turn off word wrapping, you can also use both commands with the ! (bang) symbol to toggle word wrap. So using either: :set wrap!
1. Enable the options for an individual file inside the Vim session using :set Open the desired file in Vim, type any option using the :set command in the Normal mode, and press Enter. 2. Enable the options permanently for all the files by specifying them in the local Vim configuration file ~/.
Opening vimrc Using file name completion, you could type :e $M then press Tab until you see the desired variable. If you only want to see the path, type :echo $M then press Tab to see the variable, and press Enter. In gvim, the Edit menu includes "Startup Settings" which will use $MYVIMRC to edit your vimrc file.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With