我的 Vim 配置包括set formatoptions=c,q,a
. 我对以下问题感到非常恼火(|
表示光标位置,它的确切位置无关紧要,因为您可能只知道它在此注释行中存在的事实很重要):
" This is a long line which we would like to wrap. However, something sick is go|ing to happen if we hit "gqip" here!
if has('win32') || has('win64')
set runtimepath^=~/.vim
set runtimepath+=~/.vim/after
endif
现在我们打gqip
:
" This is a long line which we would like to wrap. However, something sick is
" go|ing to happen if we hit "gqip" here!
if has('win32') || has('win64') set runtimepath^=~/.vim set
runtimepath+=~/.vim/after endif
它的作用是 - 它实际上将整个内容视为一个段落。(是的,我知道用空行分隔可以防止这种行为,但它并不能解决问题!)我希望它确实是:
" This is a long line which we would like to wrap. However, something sick is
" go|ing to happen if we hit "gqip" here!
if has('win32') || has('win64')
set runtimepath^=~/.vim
set runtimepath+=~/.vim/after
endif
换句话说,如果gq
能以某种方式忘记代码并只使用注释,那就太好了。
奖励:如何一次性在整个缓冲区上进行这种格式化(仅包装评论)?因为,理想情况下,我想将这些东西移到一个特殊的格式化挂钩中以保存文件。