假设我的 vim 文件中有以下文本:
1 "This is a function|
2 function MyFunction()
我的光标位于第 1 行的末尾(由 |
显示)。如果我按o
在该行上,它将创建如下行:
1 "This is a function
2 "|
3 function MyFunction()
即以注释字符开头的行。如何禁用此功能,以便当我按 Enter/O/O 时,它仅在现有缩进处创建换行符,忽略任何注释字符,如下所示:
1 "This is a function
2 |
3 function MyFunction()
最佳答案
来自 :h fo-table
和 :h 'formatoptions'
:
c Auto-wrap comments using textwidth, inserting the current comment
leader automatically.
r Automatically insert the current comment leader after hitting
<Enter> in Insert mode.
o Automatically insert the current comment leader after hitting 'o' or
'O' in Normal mode.
你可能想在你的 vimrc 中添加这样的内容:
set formatoptions-=cro
或者使用 autocmd 来避免 ftplugins 设置(请参阅评论):
augroup NoAutoComment
au!
au FileType * setlocal formatoptions-=cro
augroup end
关于vim - 在 vim 中按 O 或 [Return] 时不要插入注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62459817/