在vim中的评论下方插入新行? [英] inserting a new line below a comment in vim?

查看:41
本文介绍了在vim中的评论下方插入新行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 vim 中的注释下方插入新行时,结果往往会在新行的开头插入 ".这可能是一个简单的解决方案或发生这种情况的原因,但我我无法找到确切的解决方案.

While inserting a new line below a comment in vim, the result tends to insert a " at the start of the new line. It's probably a simple solution or reason why this is happening, but I am unable to find an exact solution.

推荐答案

如果您正在编辑 vim 文件类型的文件,Vim 可能会默认插入注释字符(在 Vimscript 中,这将将 ") 放在你在注释后输入的每一行的开头.如前所述,这是 Vim 的 formatoptions 设置的结果.

If you’re editing a file of the vim filetype, Vim might by default insert the comment character (in Vimscript, this would be ") at the beginning of each new line you enter after a comment. As already mentioned, this is a result of Vim’s formatoptions setting.

要在当前文件中关闭此行为,运行

:set formatoptions-=ro

要默认关闭它,将其添加到您的~/.vimrc:

set formatoptions-=ro

要为 Vimscript 文件关闭它,将其添加到您的 ~/.vimrc:

augroup filetype_vim
    autocmd!
    autocmd FileType vim setlocal formatoptions-=ro
augroup END

ro 是可以赋予​​ formatoptions 的选项.有关可能选项的完整列表,请运行 :help fo-table.

r and o are options which can be given to formatoptions. For the full list of possible options, run :help fo-table.

这篇关于在vim中的评论下方插入新行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆