vim 命令将文本重组/强制为 80 列 [英] vim command to restructure/force text to 80 columns

查看:24
本文介绍了vim 命令将文本重组/强制为 80 列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一些方法可以使用 set textwidth(例如 Vim 80 列布局问题).我正在寻找的是类似于 =(缩进行命令)的东西,但要换行到 80.用例是有时你用 textwidth 编辑文本,在加入行或删除/添加文本后,它会出现外面包装不好.

I know there are ways to automatically set the width of text in vim using set textwidth (like Vim 80 column layout concerns). What I am looking for is something similar to = (the indent line command) but to wrap to 80. The use case is sometimes you edit text with textwidth and after joining lines or deleting/adding text it comes out poorly wrapped.

理想情况下,此命令将完全重新组织我选择的行并在添加短行的同时切掉长行.一个例子:

Ideally, this command would completely reorganize the lines I select and chop off long lines while adding to short ones. An example:

long line is long!  
short

运行命令后(假设换行是 13 列):

After running the command (assuming the wrap was 13 cols):

long line is  
long! short

如果使用真正的 vim 命令无法做到这一点,也许有一个命令行程序可以执行此操作,我可以通过管道将输入传输到其中?

If this isn't possible with a true vim command, perhaps there is a command-line program which does this that I can pipe the input to?

搜索后我发现这个参考有更多的选择:http://www.cs.swarthmore.edu/help/vim/reformatting.html

After searching I found this reference which has some more options: http://www.cs.swarthmore.edu/help/vim/reformatting.html

推荐答案

Set textwidth to 80 (:set textwidth=80),移到文件开头(可以使用 Ctrl-Homegg 完成),然后输入 gqG.

Set textwidth to 80 (:set textwidth=80), move to the start of the file (can be done with Ctrl-Home or gg), and type gqG.

gqG 格式化从当前位置开始到文件末尾的文本.它会在可能的情况下自动连接连续的行.如果您不想将这两行连接在一起,您可以在两行之间放置一个空行.

gqG formats the text starting from the current position and to the end of the file. It will automatically join consecutive lines when possible. You can place a blank line between two lines if you don't want those two to be joined together.

这篇关于vim 命令将文本重组/强制为 80 列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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