当我在.{cpp,h}文件中单行注释的末尾启动一条新行时,vim将自动对其进行注释。例如:
// This is a comment<CR>
// | <- Cursor is moved to `|`, `//` is automatically inserted. 我不确定这是插件还是设置。在我的~/.vimrc中,我看不到任何看起来会这样做的东西,加载的插件如下所示。
对于/* */-style多行注释,我喜欢这样,但默认情况下,我不希望我的单行注释在多行上运行。
哪个设置(或插件)可以这样做,我可以关闭它只对此注释类型?
:scriptnames给出了以下内容:
1: /Users/simont/.vimrc
2: /usr/local/share/vim/vim73/syntax/syntax.vim
3: /usr/local/share/vim/vim73/syntax/synload.vim
4: /usr/local/share/vim/vim73/syntax/syncolor.vim
5: /usr/local/share/vim/vim73/filetype.vim
6: /usr/local/share/vim/vim73/ftplugin.vim
7: /usr/local/share/vim/vim73/syntax/nosyntax.vim
8: /Users/simont/repositories/config-files/vim/colors/solarized.vim
9: /usr/local/share/vim/vim73/plugin/getscriptPlugin.vim
10: /usr/local/share/vim/vim73/plugin/gzip.vim
11: /usr/local/share/vim/vim73/plugin/matchparen.vim
12: /usr/local/share/vim/vim73/plugin/netrwPlugin.vim
13: /usr/local/share/vim/vim73/plugin/rrhelper.vim
14: /usr/local/share/vim/vim73/plugin/spellfile.vim
15: /usr/local/share/vim/vim73/plugin/tarPlugin.vim
16: /usr/local/share/vim/vim73/plugin/tohtml.vim
17: /usr/local/share/vim/vim73/plugin/vimballPlugin.vim
18: /usr/local/share/vim/vim73/plugin/zipPlugin.vim
19: /usr/local/share/vim/vim73/scripts.vim
20: /usr/local/share/vim/vim73/ftplugin/vim.vim
21: /usr/local/share/vim/vim73/syntax/vim.vim发布于 2012-05-23 19:17:49
au FileType c,cpp setlocal comments-=:// comments+=f://在您的vimrc中,在{cpp,h}文件中,应该在不影响块注释的情况下对//执行此操作。
若要在当前缓冲区中临时尝试它,请使用:
:setlocal comments-=:// comments+=f://发布于 2012-05-23 20:41:46
这种与特定文件类型相关的配置通常是通过文件类型插件来设置的。Vim附带了许多常见文件类型(如.cpp)的文件类型。您可以使用:set ft?检查缓冲区的文件类型。
启动新行后继续注释的设置来自选项'comments',正如pb2q所说。对于.{cpp,h},默认的文件类型是'cpp',而'comment'选项设置在$VIMRUNTIME/ftplugin/c.vim,因为cpp.vim位于同一个目录中。来自c.vim文件:
" Set 'comments' to format dashed lists in comments.
setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://comments选项是一个{flags}:{string}列表,标志为f和O避免扩展注释新行。
来自Vim常见问题
You can use an autocommand triggered on the FileType event:
au Filetype * set formatoptions=xyz
This should at least be after "filetype on" in your vimrc. Best is to put
it in your "myfiletypefile" file, so that it's always last.
If you want to override a setting for a particular filetype, then create a
file with the same name as the original filetype plugin in the
~/.vim/after/ftplugin directory For example, to override a setting in the
c.vim filetype plugin, create a c.vim file in the ~/.vim/after/ftplugin
directory and add your preferences in this file.所以创建文件~/.vim/after/ftplugin/c.vim与
setlocal comments-=://
setlocal comments+=fO://应该解决问题。
发布于 2020-05-21 18:21:55
可以使用在FileType事件上触发的自动命令:
au Filetype * set formatoptions=xyz这至少应该在您的vimrc中的"filetype on“之后。最好是把它放在你的"myfiletypefile“文件中,这样它就永远是最后的了。
如果要重写特定文件类型的设置,则在~/..vim/after/ftplugin目录中创建一个与原始文件类型插件同名的文件--例如,要重写c.vim文件类型插件中的设置,请在~/..vim/after/ftplugin目录中创建一个c.vim文件,并在该文件中添加首选项。所以用以下方式创建文件~/..vim/后/ftplugin/c.vim
setlocal注释-=:// setlocal注释+=fO://
https://stackoverflow.com/questions/10726373
复制相似问题