Auto wrap long lines in VIM
Asked Answered
D

3

19

When I edit a haskell file in Vim, my editor automatically wraps comments that go past 80 characters to the next line. I'd like Vim to use the same behavior for python files (and text files), but I can't find the setting that does this anywhere, in my ~/.vim/syntax folder or vimrc.

Here are relevant lines of my .vimrc:

set wrap
set textwidth=80
Dicot answered 9/4, 2011 at 4:36 Comment(0)
M
13

Setting textwidth will put your maximum line length. This would put a new line at that character point (white space could play with an exact 80 a bit though). (This effects the actual formatting of your file).

wrap is indeed what you want for your splitting/wrapping though.

Make sure your .vimrc is in your home directory.

Maxie answered 9/4, 2011 at 5:31 Comment(2)
This question on stackoverflow talks about some python wrapping stuff as well #1314674Maxie
Thanks - I think adding "c" to my formatoptions helped solve the problem.Dicot
D
5

I uses the following script in my vimrc to wrap .txt file automatically. This may give you some hints.

if has('autocmd')
  au BufRead,BufNewFile *.txt set wm=2 tw=80
endif
Dyscrasia answered 9/4, 2011 at 7:2 Comment(1)
If textwidth != 0 then wordmargin is ignored.Coati
G
2

If a line is already longer than textwidth when insert mode is started, the line may not be wrapped even if text is added to the line. A long line is not wrapped when text is added if formatoptions contains "l". If needed, "l" can be removed like so:

:set fo-=l

You can check the value of your formatoptions via:

:set fo?

You can learn the meaning of those letters here or via:

:he fo-table
Gustave answered 12/11, 2018 at 20:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.