博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vim中实现括号和引号自动补全
阅读量:7012 次
发布时间:2019-06-28

本文共 2940 字,大约阅读时间需要 9 分钟。

将下面内容加入.vimrc文件中即可
inoremap ( ()
iinoremap [ []
iinoremap { {
}
Oautocmd Syntax html,vim inoremap <
>
i| inoremap >
=ClosePair('>')
inoremap )
=ClosePair(')')
inoremap ]
=ClosePair(']')
inoremap }
=CloseBracket()
inoremap "
=QuoteDelim('"')
inoremap '
=QuoteDelim("'")
function ClosePair(char) if getline('.')[col('.') - 1] == a:char return "\
" else return a:char endifendffunction CloseBracket() if match(getline(line('.') + 1), '\s*}') < 0 return "\
}" else return "\
j0f}a" endifendffunction QuoteDelim(char) let line = getline('.') let col = col('.') if line[col - 2] == "\\" "Inserting a quoted quotation mark into the string return a:char elseif line[col - 1] == a:char "Escaping out of the string return "\
" else "Starting a string return a:char.a:char."\
i" endifendf

  

 

 

其他相关:

autocomplete.match.pair.vim

inoremap ( 
=OpenPair('(')
inoremap )
=ClosePair(')')
inoremap {
=OpenPair('{')
inoremap }
=ClosePair('}')
inoremap [
=OpenPair('[')
inoremap ]
=ClosePair(']')
" just for xml document, but need not for now."inoremap <
=OpenPair('<')
"inoremap >
=ClosePair('>')
function! OpenPair(char) let PAIRs = { \ '{' : '}', \ '[' : ']', \ '(' : ')', \ '<' : '>' \} if line('$')>2000 let line = getline('.') let txt = strpart(line, col('.')-1) else let lines = getline(1,line('$')) let line="" for str in lines let line = line . str . "\n" endfor let blines = getline(line('.')-1, line("$")) let txt = strpart(getline("."), col('.')-1) for str in blines let txt = txt . str . "\n" endfor endif let oL = len(split(line, a:char, 1))-1 let cL = len(split(line, PAIRs[a:char], 1))-1 let ol = len(split(txt, a:char, 1))-1 let cl = len(split(txt, PAIRs[a:char], 1))-1 if oL>=cL || (oL
=cl) return a:char . PAIRs[a:char] . "\
" else return a:char endifendfunctionfunction! ClosePair(char) if getline('.')[col('.')-1] == a:char return "\
" else return a:char endifendfinoremap '
=CompleteQuote("'")
inoremap "
=CompleteQuote('"')
function! CompleteQuote(quote) let ql = len(split(getline('.'), a:quote, 1))-1 let slen = len(split(strpart(getline("."), 0, col(".")-1), a:quote, 1))-1 let elen = len(split(strpart(getline("."), col(".")-1), a:quote, 1))-1 let isBefreQuote = getline('.')[col('.') - 1] == a:quote if '"'==a:quote && "vim"==&ft && 0==match(strpart(getline('.'), 0, col('.')-1), "^[\t ]*$") " for vim comment. return a:quote elseif "'"==a:quote && 0==match(getline('.')[col('.')-2], "[a-zA-Z0-9]") " for Name's Blog. return a:quote elseif (ql%2)==1 " a:quote length is odd. return a:quote elseif ((slen%2)==1 && (elen%2)==1 && !isBefreQuote) || ((slen%2)==0 && (elen%2)==0) return a:quote . a:quote . "\
" elseif isBefreQuote return "\
" else return a:quote . a:quote . "\
" endifendfunction

  

 

 

转载地址:http://ujqtl.baihongyu.com/

你可能感兴趣的文章
MySQL参数优化及基础操作
查看>>
浏览器输入 \\192.168.0.1 和 192.168.0.1 的区别
查看>>
Javascript之【函数回调】
查看>>
linux 常用命令---hashlinux整理收集
查看>>
体系结构之4+1view
查看>>
Nginx的安装 Centos
查看>>
mybatis-generator配置
查看>>
Eclipse插件大全
查看>>
腾讯击败EA/暴雪 成全球第四大游戏公司
查看>>
学习笔记04.09
查看>>
用list 接 数值,再讲数值转成 整形数组,排序、再将相邻的数用范围形式表示、...
查看>>
《Android开发从零开始》——7.Intent初级学习
查看>>
Cacti weathermap添加实时读数节点
查看>>
Linux就该这么学
查看>>
Qmail 邮件系统维护管理技术文档
查看>>
Google Guava - Cache
查看>>
你以为的SPSS只是简单的数据分析软件吗?
查看>>
CSS Grid Simple Example
查看>>
《Windows服务器配置与管理》本地用户、组的管理
查看>>
mysql数据库移植sqlserver数据库
查看>>