问题描述
我花费了方式太多时间摸索,因为 Vim 不像大多数 IDE 那样处理右大括号.这是我想要发生的事情:
I spend way too much time fumbling around because Vim doesn't handle closing braces like most IDEs do. Here's what I want to happen:
输入:
if( whatever )
{ <CR>
得到这个:
if( whatever )
{
|
}
其中 表示按下 键,
|
是光标的位置.这就是 Eclipse 所做的.这就是 Visual Studio 所做的.这就是我想让 Vim 做的事情.
where <CR>
mean hit the key and |
is the position of the cursor. This is what Eclipse does. It's what Visual Studio does. And it's what I want Vim to do.
我看过一些插件,尝试了一些,但似乎没有一个给我这种行为.我当然不会是第一个想要这个的程序员.
I've seen a few plugins, tried a few, and none of them seem to give me this behavior. Surely I can't be the first programmer to want this.
推荐答案
在 VimL 中,您可以映射 {
以完全按照您的意愿执行:
In VimL, you can map the {
to do exactly as you wish:
inoremap { {<CR>}<Esc>ko
根据您的自动缩进设置,您可能希望在 之后添加
.
depending on your autoindent setup, you may want to add a <BS>
after <CR>
.
要获得更完整的解决方案,我建议您查看 Luc Hermitte 的 vim 插件.到目前为止,他们从未让我失望过.
For a more complete solution, I'd suggest you take a look at Luc Hermitte's vim plugins. They've never failed me so far.
这篇关于在 Vim 中自动插入匹配的大括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!