In VIM, how do I break one really long line into m

2020-05-10 18:58发布

Say I have a super long line in the VIM editor (say around 300+ characters). How would I break that up into multiple lines so that the word boundaries roughly break at 80 characters?

Example:

This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line This is a really long line

to

This is a really long line 
This is a really long line
This is a really long line
This is a really long line
This is a really long line
This is a ...

标签: vim
9条回答
霸刀☆藐视天下
2楼-- · 2020-05-10 19:38

This is not really related to VIM, but you could use the fmt program as in

$ fmt myfile
查看更多
冷血范
3楼-- · 2020-05-10 19:39

If you're on *nix you probably have fold available.

Select the region you want using v, then you can break on spaces at width 80 using:

!fold --spaces --width=80

This is esentially the same as using gq.

However, if you just want to break at character 80 and not be restricted to whitespaces you can use:

!fold --width=80

If you want it with one keystroke just set a mapping - I've used

vmap <f1> !fold --width=80<CR>

查看更多
疯言疯语
4楼-- · 2020-05-10 19:41

First set your vim so that it understands that you want 80 characters:

:set tw=80

then, hilight the line:

V

and make vim reformat it:

gq
查看更多
登录 后发表回答