按下 Enter 时如何阻止 Vim 自动插入注释引导符? [英] How to stop Vim from automatically inserting the comment leader when Enter is pressed?
本文介绍了按下 Enter 时如何阻止 Vim 自动插入注释引导符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我像这样在 gVim 中输入评论
If I'm typing a comment in gVim like this
//这是一条评论
然后我按 ENTER,它会自动以//开始下一行,所以它看起来像这样:
and I hit ENTER, it will automatically start the next line with //, so it looks like this:
// this is a comment
//
但通常我不想在使用这种评论风格时写更多评论.我可以阻止 gVim 自动执行此操作,同时仍保持/* .. */注释样式的自动完成吗?
But usually I don't want to write more comments when using this commenting style. Can I stop gVim from automatically doing this, while still keeping the auto-completing of the /* .. */ commenting style?
推荐答案
我的另一个答案,因为您不想为 /*
... */
触发> 评论.
Another answer from mine since you don't want to have this triggered for /*
… */
comments.
使用:
inoremap <expr> <enter> getline('.') =~ '^\s*//' ? '<enter><esc>S' : '<enter>'
对于 o
和 O
:
nnoremap <expr> O getline('.') =~ '^\s*//' ? 'O<esc>S' : 'O'
nnoremap <expr> o getline('.') =~ '^\s*//' ? 'o<esc>S' : 'o'
这篇关于按下 Enter 时如何阻止 Vim 自动插入注释引导符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文