vim补全html标签,vim括号引号html标签自动补全
(我現在已經不用下面方法了,可使用 xptemplate插件?http://blog.csdn.net/zcube/article/details/42525973)
問題:怎樣在vim中實現花括號引號自動補全,包括html標簽?
解決辦法:只要把下面兩段代碼粘貼到~/.vimrc中,就可以實現括號超強補全
" 括號引號補全
inoremap ( ()i
inoremap [ []i
inoremap { {}O
inoremap ) =ClosePair(')')
inoremap ] =ClosePair(']')
inoremap } =CloseBracket()
inoremap " =QuoteDelim('"')
inoremap ' =QuoteDelim("'")
function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\"
else
return a:char
endif
endf
function CloseBracket()
if match(getline(line('.') + 1), '\s*}') < 0
return "\}"
else
return "\j0f}a"
endif
endf
function 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"
endif
endf
" html自動補全
autocmd BufNewFile * setlocal filetype=html
function! InsertHtmlTag()
let pat = '\c'
normal! a>
let save_cursor = getpos('.')
let result = matchstr(getline(save_cursor[1]), pat)
"if (search(pat, 'b', save_cursor[1]) && searchpair('','bn',0, getline('.')) > 0)
if (search(pat, 'b', save_cursor[1]))
normal! lyiwf>
normal! a
normal! p
normal! a>
endif
:call cursor(save_cursor[1], save_cursor[2], save_cursor[3])
endfunction
inoremap > :call InsertHtmlTag()aO
之所以這里的括號補全代碼中的函數實現反匹配
當打入(輸入內容),再按)系統會自動檢查前面是否已經有匹配的括號
如果有就不再鍵入),而是直接跳出
或許你得加:
set autoindent
set cindent
參考:
http://www.cnblogs.com/huanlei/archive/2012/04/02/2430153.html
http://blog.sina.com.cn/s/blog_01ea59580101hvth.html
總結
以上是生活随笔為你收集整理的vim补全html标签,vim括号引号html标签自动补全的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 上所说的计算机主机是什么意思,通常所说的
- 下一篇: 台式计算机是32位还64位,怎么看电脑是