视觉选择并中断VIM中的多行,最大宽度为文本宽度

  • 本文关键字:文本 选择 中断 VIM 视觉 vim
  • 更新时间 :
  • 英文 :


如果我有一些像这样的长行

# I am Quater. Read my words, and be my friend.
# Father commands me to record the truth of history, so that readers will learn from those who went before.
# Therefore, I give each of my seven sons one of these self-engraving, history-recording klay walls.

我想选择行并发出命令,使其换行到文本宽度,同时保留注释符号(标签(以获得以下

# I am Quater. Read my words, and be my friend.
# Father commands me to record the truth of 
# history, so that readers will learn from 
# those who went before. Therefore, I give each 
# of my seven sons one of these self-engraving, 
# history-recording klay walls.

我知道有一种方法可以做到这一点,因为我以前在VIM中做过,但我删除了我的.vimrc文件,在谷歌上找不到解决方案

您可以使用gq命令让Vim格式化行。直观地选择行,然后使用gq,或者使用gq后跟一个动作(例如gq},格式化到下一行(,或者使用带计数的gqq(3gqq,格式化当前行和后面的两行(。

Vim要保留注释,需要正确设置两个选项。一个是'formatoptions',它需要包括q(在gq操作上保留注释(,以及'comments'选项,它需要包含b:#,以指示以#开头的行是注释。

您可以使用为当前缓冲区设置两者

setl fo+=q com+=b:#

在这些设置之后,使用gq将在自动格式化注释块时将注释字符保持在行的开头。

最新更新