在 VIM 中,如何将一条很长的行分成多行? [英] In VIM, how do I break one really long line into multiple lines?

查看:46
本文介绍了在 VIM 中,如何将一条很长的行分成多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在 VIM 编辑器中有一条超长的行(比如大约 300 多个字符).我如何将其分成多行,以便单词边界大致在 80 个字符处中断?

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?

示例:

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

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 做到这一点很容易(在单词边界处换行).

Vim does this very easy (break lines at word boundaries).

gq{motion} % format the line that {motion} moves over
{Visual}gq % format the visually selected area
gqq        % format the current line
...

我建议你查看 :help gq:help gw.

I'd suggest you check out :help gq and :help gw.

同时设置 textwidth (tw) 会在打字过程中超过时自动换行.它也在 gq 中使用,但如果禁用 gq 在窗口大小或 79 上中断,取决于哪个先出现.

Also setting textwidth (tw) will give you auto line break when exceeded during typing. It is used in gq too, though if disabled gq breaks on window size or 79 depending on which comes first.

:set tw=80

通过设置格式选项以包含文本宽度,vim 将在 tw 设置处自动中断.

By setting format options to include text width vim will automatically break at the tw setting.

:set fo+=t

这篇关于在 VIM 中,如何将一条很长的行分成多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆