如何在 vim 中手动插入匹配的大括号?

How to insert matching brace in vim MANUALLY?

我的缓冲区中有一些文本

[{(lorem) ipsum <cursor here>

如何插入右大括号 },然后键入内容,然后插入与左大括号 {[

匹配的 ]

让我解释一下为什么我需要这个。

例如我必须输入一些纯javascript代码(因为目前coffee机器出故障了)

$(document).ready(function(){
  var classA = (function(){
     function classA(){}
     <100 lines of code here>
     return classA;
  -->oh, which closing brace should I insert here....!

另一种情况

[theWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", HostName, @"some/path/here"]] -> huh, what next? How many closing braces am I missing?

以及为什么我在问题标题中手动澄清。 Because there are some key bindings to automatically insert 右大括号。例如 in ( ()<Left>。但是,我只想在需要时插入右大括号。

我知道有 i_<C-x>_<C-o> 可以插入结束 xml 标签。但是我不知道怎么处理这些。

提前谢谢你。

最后,我想出了这个 vim-close-pair 插件。

只需键入<Ctrl-L>(插入模式),它会自动找到并插入缺失的大括号。

  • 安装 Vundle:

    • Plugin 'nissasssin17/vim-close-pair 附加到您的 .vimrc 文件
    • 重新启动 vim 或 运行 :source ~/.vimrc
    • 运行 :PluginInstall
  • 手动安装:

      git checkout https://github.com/nissassin17/vim-close-pair.git
      cd vim-close-pair
      mkdir -p ~/.vim/plugin
      cp -f plugin/close-pair.vim ~/.vim/plugin/
      mkdir -p ~/.vim/autoload
      cp -f autoload/close-pair.vim ~/.vim/autoload/