Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在VIM中快速重新分配每行的字数/字符数_Vim_Text - Fatal编程技术网

在VIM中快速重新分配每行的字数/字符数

在VIM中快速重新分配每行的字数/字符数,vim,text,Vim,Text,对于在vim中编写的文本,当我需要编辑一行/添加一些新文本时,每行的字数都不正常 是否有一种快速重新调整/换行的方法来均匀分散VIM中每行的字数 80个字符自动换行的示例: 编辑前 This is something that I have writting with automatic line-wrapping before I have edited the file. I'll write some more just for demonstration purposes for th

对于在
vim
中编写的文本,当我需要编辑一行/添加一些新文本时,每行的字数都不正常

是否有一种快速重新调整/换行的方法来均匀分散VIM中每行的字数

80个字符自动换行的示例:

编辑前

This is something that I have writting with automatic line-wrapping before I 
have edited the file. I'll write some more just for demonstration purposes for
this whole line wrapping problem of mine.
This is something that I have writting with automatic line-wrapping after I
have edited the file. I'm demonstrating
this whole line wrapping problem of mine.
编辑后

This is something that I have writting with automatic line-wrapping before I 
have edited the file. I'll write some more just for demonstration purposes for
this whole line wrapping problem of mine.
This is something that I have writting with automatic line-wrapping after I
have edited the file. I'm demonstrating
this whole line wrapping problem of mine.
手动修复这些是一个令人厌烦的问题,尤其是如果我修复了它并继续编辑内容的话

我的梦想

如果我可以使用
shit+v
直观地选择多行,然后自动分配每行的字数,那就太完美了。

  • 选择当前段落,然后
  • gqto使用textwidth重新格式化段落

  • gqip组合运算符和范围(有关详细信息,请参阅
    :help text objects
如果您经常使用它,您可能可以重新映射一个新命令,该命令将执行前面提到的两个命令


有关详细信息,请参见
:help gq

您可以根据需要设置
textwidth
选项(或简称
tw
) 宽度。比如说80

:set tw=80
现在,使用内置格式设置程序或自定义格式设置程序 命令
gq
。查看有关已知的
gq
gw
'formatprg'
的帮助 更多这与运动一起使用。因此,要重新格式化当前段落, 执行gqip
。整个文本,
gggqG
(光标指向顶部(
gg
)然后格式化 直到底部)。还有其他各种各样的运动

此外,请查看有关格式选项的帮助(
:h'fo'
:h fo表
)。您特别感兴趣的选项是
A
。所以如果 你可以:

现在您甚至不需要重新格式化任何内容。Vim将继续检查 在您输入和重新设置段落格式时的行宽 通过插入或删除换行符

我喜欢外部程序的灵活性,也推荐您 看看他们。例如,此答案的降价格式为
UNIX程序。检查原始文本。

在“编辑后”中,缓冲区中有多少行?所有文本都在一行吗?自动换行会将超出定义限制(上面80个字符)的文本移动到下一行,因此它们不在一行上。我更喜欢这种方式,因为它使用光标移动命令(例如,
h
j
k
l
,等等)可以更轻松地导航文本。缓冲区中的行可能会有所不同,我正在寻找一种通用方法,用于编辑不同文件(例如纯文本、LaTeX、reStructuredText、MarkDown等)这也适用于
shift+v
。梦想成真。谢谢泽维尔!!!这对我来说是一个改变游戏规则的因素:)
vip
+
gq
可以改为
gqip
。非常适合自动重新格式化。选择此选项作为附加信息的最佳答案。还是要感谢泽维尔!我现在已经尝试了自动格式化,它对我来说非常有用。@ryanjdillon很高兴知道!很高兴它帮助了你。最美好的祝福