Vim formatoptions- =或

7 vim

我的vimrc中有以下几行:

" Don't add the comment prefix when I hit enter or o/O on a comment line.
set formatoptions-=or
Run Code Online (Sandbox Code Playgroud)

它曾经在某个时候起作用.我不知道我做了什么,但它不再存在,我在创建换行符时仍然会收到评论.有什么可以禁用它?这是我的vimrc:http://pastebin.com/kVWWeQWW

mMo*_*ntu 12

如果您在启动后发现该标志o正在插入formatoptions,您应该找出发生这种情况的原因并进行修复.autocmd即使在删除选项后,这似乎比总是执行一个更干净.

您可以使用以下命令检查发出选项的位置:

:5verbose set fo?
:5verbose setl fo?
Run Code Online (Sandbox Code Playgroud)

编辑:

如果您的问题ftplugin在于Vim目录($VIMRUNTIME/ftplugin)上的文件,则不应更改该文件,因为在更新Vim时该更改将被撤消.更改它的正确方法是在您的after目录中,如中所述:h after-directory.

假设cfiletype 出现问题,请创建~/.vim/after/ftplugin/c.vim包含setlocal formatoptions-=命令的文件.


Ory*_*and 9

@ mm2703的解决方案对我不起作用,特别是对于java文件,但这种改变确实如此.我还把它包装成一份augroup声明,所以资源.vimrc不会重新注册autocmd:

augroup Format-Options
    autocmd!
    autocmd BufEnter * setlocal formatoptions-=c formatoptions-=r formatoptions-=o

    " This can be done as well instead of the previous line, for setting formatoptions as you choose:
    autocmd BufEnter * setlocal formatoptions=crqn2l1j
augroup END
Run Code Online (Sandbox Code Playgroud)


Pau*_*aul 7

如果您'formatoptions'包含不同顺序的选项ro,那么-=or将无效.尝试

set formatoptions-=o
set formatoptions-=r
Run Code Online (Sandbox Code Playgroud)

来自help remove-option-flags:

请注意,您应该一次添加或删除一个标志.如果'guioptions'的值为"ab",则使用"set guioptions- = ba"将不起作用,因为字符串"ba"不会出现.


小智 6

我意识到:set formatoptions?,虽然该o标志在启动时被禁用,但在打开文件时它又回来了。这在我的 vimrc 中修复了它:

" Don't add the comment prefix when I hit enter or o/O on a comment line.
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
Run Code Online (Sandbox Code Playgroud)