首页 > 解决方案 > 在 vim 中使用多个游标时禁用自动配对

问题描述

我正在使用 vim 插件 vim-multiple-cursors 和 auto-pairs。例如,如果我正在编辑一段文本:

one
two
three
four

如果我用命令突出显示块

vip <ctrl-n> I "

这将在前面创建两个括号,因为自动配对处于活动状态。

""one
""two
""three
""four 

当您使用 vim-multiple 游标时,有没有办法让自动配对自动关闭?

set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

""""""""" PLUGIN LIST STARTS HERE """"""""""""""""""""
Plugin 'VundleVim/Vundle.vim'
Plugin 'scrooloose/syntastic'
Plugin 'jiangmiao/auto-pairs'
Plugin 'tpope/vim-surround'
Plugin 'ervandew/supertab'
Plugin 'terryma/vim-multiple-cursors'
Plugin 'tpope/vim-repeat'
Plugin 'scrooloose/nerdtree'
""""""""" PLUGIN LIST END HERE """"""""""""""""""""
call vundle#end()            " required
filetype plugin indent on    " requiredntax on

syntax on
set tabstop=4
set number
set smartindent
set shiftwidth=4
set mouse=a
set backspace=indent,eol,start

let &t_SI.="\e[5 q"
let &t_SR.="\e[4 q"
let &t_EI.="\e[1 q"

let g:NERDTreeDirArrowExpandable = '▸'
let g:NERDTreeDirArrowCollapsible = '▾'
map <F5> :NERDTreeToggle<CR>

let g:syntastic_cpp_compiler = 'clang++'
let g:syntastic_cpp_compiler_options = ' -std=c++11 -stdlib=libc++'

标签: vimvim-pluginmultiple-cursor

解决方案


Autopairs 有一个调用的函数AutoPairsToggle(),您需要在进入多个光标模式之前和之后调用该函数。

vim-multiple-cursors为您提供了一种解决插件交互的方法:定义一个 pre 和 post 钩子:

function! Multiple_cursors_before()
  call AutoPairsToggle()
endfun

function! Multiple_cursors_after()
  call AutoPairsToggle()
endfun

把这些放在你.vimrc的,问题应该不再发生。


推荐阅读