编写 int main(){} 的更好方法

A better way to write int main(){}

我最近开始使用 vim。
当我开始编码时,我通常从以下格式开始。
('_' 表示光标的位置。)

int main(){ 
    _
}

这是我所做的
1. 输入 int main(){}
2. ctrl-o h(向左移动)
3.输入两次
4. ctrl-o k(向上移动)
5.制表符(缩进)

问题是,它需要太多的击键。
我想知道是否有更好的方法来做到这一点。

C&C++main()这么简单的东西都已经定义在所有snippet plugins and even in specialized plugins like lh-cpp (I'm maintaining this one) or c.vim.

你也可以自己用缩写来完成,但是你必须检测你是在代码中还是在 string/comment 上下文中。您可以定义自己的代码片段插件,但已经有很多这样的插件了。

snippets 就像类固醇的内置 :abbreviate 一样,通常在其中包含参数插入、镜像和多个停止。 snipMate (inspired by the TextMate editor); unfortunately, it's not maintained any more; though there is a fork. A modern alternative (that requires Python though) is UltiSnips. There are more, see this list on the Vim Tips Wiki.

是第一个非常有名(并且仍然被广泛使用)的 Vim 插件

评价三点:一是snippet引擎本身的特点,二是作者或他人提供的snippet的质量和广度;第三,添加新片段是多么容易。