0008 Vim Bracket Quote HTML tag Auto complement

Source: Internet
Author: User

Question: How do I implement a curly brace quote auto-complete in vim, including HTML tags? Workaround: As long as the following two pieces of code pasted into ~/.VIMRC, you can implement the parentheses to complete the full <!--bracket quotation mark complete code {{{--> "bracket quotation mark complement Inoremap (() <esc>iinoremap [[]<esc >iinoremap {{<cr>}<esc>oinoremap) <c-r>=closepair (') ') <cr>inoremap] <c-r>= Closepair ('] ') <cr>inoremap} <c-r>=closebracket () <cr>inoremap "<c-r>=quotedelim ('") < Cr>inoremap ' <c-r>=quotedelim ("')") <cr>function Closepair (char) if getline ('. ') [Col ('. ')-1] = = A:charreturn "\<right>" Elsereturn a:charendifendffunction closebracket () if Match (Getline (line ( '.') + 1), ' \s*} ') < 0return "\&LT;CR&GT;}" Elsereturn "\<esc>j0f}a" Endifendffunction Quotedelim (char) Let line = Getline ('. ') Let col = col ('. ') If line[col-2] = = "\" "Inserting a quoted quotation mark into the Stringreturn a:charelseif line[col-1] = = A:char" Esca Ping out of the Stringreturn "\<right>" Else "starting a stringreturn A:char.a:char." \<esc>i "endifendf<!--}}}--><!--HTML Tag Auto-complete {{{--> "HTML auto-complete autocmd bufnewfile * setlocal filetype=htmlfunction! Inserthtmltag () Let Pat = ' \c<\w\+\s*\ (\s\+\w\+\s*=\s*[' #$;, (). " a-z0-9]\+\) *\s*> ' 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! pnormal! A>endif:call cursor (save_cursor[1], save_cursor[2], save_cursor[3]) endfunctioninoremap > <esc>:call Inserthtmltag () <CR>a<CR><Esc>O<!--}}}--> The function in the completion code of the parentheses here is matched when entering (input content) and then pressing) The system automatically checks to see if there are any matching parentheses, if any, but instead of typing it out, you might want to add: Set Autoindentset cindent reference: http://www.cnblogs.com/huanlei/archive/2012 /04/02/2430153.htmlhttp://blog.sina.com.cn/s/blog_01ea59580101hvth.html

0008 Vim Bracket Quote HTML tag Auto complement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.