Auto wrap long lines in VIM

本小妞迷上赌 提交于 2019-12-04 22:45:29

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.

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

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!