vim - 在 vim 中按 O 或 [Return] 时不要插入注释

标签 vim

假设我的 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/

相关文章:

Vim supertab 和 jedi-vim

vim - 为什么 `filetype on` 在 vi​​m 中检测不到文件类型?

c++ - 在vim中显示函数调用堆栈

vim - 如何遵循 vim 高尔夫解决方案

java - 无法在vim中更新jar中的文件

vim - `set foldmethod=syntax`让vim变慢,`set foldmethod=indent`不够好,怎么办?

vim - Vim 关闭时出现错误消息

vim - 在 Vim 中跨页选择?

vim - 如何在 VIM 中画线?

vim - 在 VIM 中缩进后如何转到行首?