Vim: How to reformat a set of lines into a single line (if the line is a single sentence)?

跟風遠走 提交于 2019-12-12 13:10:03

问题


Not a dup of In Vim, what is the simplest way to join all lines in a file into a single line?, as I specifically mean to use the gq reformatting functionality.

I used to write latex in vim using 80 character textwidth. However, I've now switched to an infinite textwidth, so my lines go on forever.

Vim's reformatting (gqap for example), combines a few lines into a paragraph, wrapping them at 80 characters. I'd like it to instead combine them into a single line.

ie

Without a \clang{goto} statement in the HIR, we must instead use conditional
statements to check the iteration number.

should reformat into

Without a \clang{goto} statement in the HIR, we must instead use conditional statements to check the iteration number.

when it is highlighted and gq is pressed.


回答1:


If you don't like "J" as depesz suggested then do

:set tw=9999

Then do 'gq'. Adjust tw to your needs.




回答2:


Why don't you just "J" the lines after you select them?



来源:https://stackoverflow.com/questions/1450904/vim-how-to-reformat-a-set-of-lines-into-a-single-line-if-the-line-is-a-single

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