Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
227 views
in Technique[技术] by (71.8m points)

How to automatically disable hardwraps when making a list in vim?

For people who use hardwrapping in vim via:

set tw=80
set fo=ta
# Or similiar

As you write/edit paragraphs of text it will add hardwraps as intended. However, by default the above settings are not very clever when one is trying to edit lists, e.g.:

- item 1
- item 2
- item 3

As soon as you edit any item on the list vim will join the three lines together to form one single paragraph. Was wondering if vim could be configured so it can intelligently disable / enable hardwrap.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As far as I know, it isn't possible to adjust whether wrapping is enabled on a line-by-line basis. However, if you're comfortable with having your lists be wrapped on subsequent lines, you can set the following:

set autoindent
set formatoptions+=n
set formatlistpat=^[-*+?]\+\s\+

That will result in long item lines looking like this:

- This is one single, very, extremely long
  item.
- This is the second item.

That will also have the same effect if you use the gq motion to format. In both cases, Vim won't wrap the list items together.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.7k users

...