Automatic completion of parentheses and quotation marks in vim

Source: Internet
Author: User

Add the following content to the. vimrc file.

Inoremap (() <esc>iinoremap [[]<esc>iinoremap {{<cr>}<esc>oautocmd Syntax Html,vim Inoremap & Lt <lt>><esc>i| Inoremap > <c-r>=closepair (' > ') <cr>inoremap) <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:char return "\<right>" else return A:char endifendffunction closebracket () if Match (Getline (line (‘.‘) + 1), ' \s*} ') < 0 return "\&LT;CR&GT;}" Else return "\<esc>j0f}a" Endifendffunction Quotedelim (char) let line = g Etline ('. ') Let col = col ('. ') if line[col-2] = = "\ \" "Inserting a quoted quotation mark into the string return A:char E Lseif Line[col-1] = = A:char "Escaping out of the string return" \<right> "Else" starting a string return A:CHAR.A: Char. " \<esc>i "EndiFendf

Automatic completion of parentheses and quotes in vim

Related Article

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.