自动插入在Vim的一个匹配的括号 [英] Automatically insert a matching brace in Vim

查看:376
本文介绍了自动插入在Vim的一个匹配的括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花的办法的太多时间摸索周围因为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 )
{
  |  
}

其中,&LT; CR&GT; 意味着按<大骨节病> ENTER 键和 | 是光标位置。这是Eclipse中做了什么。这是什么样的Visual Studio一样。而且这是我想Vim做的。

where <CR> mean hit the ENTER 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

根据您的自动缩进设置,您可能需要添加一个&LT; BS&GT; &LT; CR&GT;

有关更完整的解决方案,我建议你看一看吕克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的一个匹配的括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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