Vim edit Java JavaScript auto-completion {([and add points at the end of the line when entering a semicolon

Source: Internet
Author: User
Tags imap

"================================================================== Auto-closing brackets = ======================================
Function! My_bracketcomplete ()
Let char = strpart (Getline ('.'), COL ('.')-1, 1)
If (char = ")")
Return "/<right>"
Else
Return ")"
Endif
Endfunction
Autocmd filetype Java, JavaScript, html imap () <left>
Autocmd filetype Java, JavaScript, HTML inoremap) <C-R> = my_bracketcomplete () <CR>

Function! My_midcomplete ()
Let char = strpart (Getline ('.'), COL ('.')-1, 1)
If (char = "]")
Return "/<right>"
Else
Return "]"
Endif
Endfunction
Autocmd filetype Java, JavaScript, html imap [[] <left>
Autocmd filetype Java, JavaScript, HTML inoremap] <C-R> = my_midcomplete () <CR>

Autocmd filetype Java, JavaScript, HTML, css imap {<ESC> XA <ESC> Pa} <left> <CR> <up> <tab>
Function! My_bracecomplete ()
Let char = strpart (Getline ('.'), COL ('.')-1, 1)
If (char = "}")
Return "/<right>"
Else
Return "}"
Endif
Endfunction

Function! My_appendsemicolon () "after adding a semicolon at the end of the sentence, the cursor is still back to the original position IMAP; <C-R> = my_appendsemicolon () <CR>
Let nowpos = COL ('.') "cursor subscript
Let endpos = COL ('$') "End subscript
Let Len = endpos-nowpos
Let line = Getline ('.')
If matchend (line, "; // s/* $") = strlen (line) "If this row ends with a semicolon (including spaces after the semicolon) the semicolon is not added to the end, but at the cursor.
Return ";"
Else
Return repeat ("/<right>", Len). ";". Repeat ("/<left>", Len + 1) "add a semicolon at the end of a row and return to the original location
Endif
Endfunction
"======================================== End of brackets automatically closed ======== ============================
"When used in combination with omni, The system. Out. Print (
"Instead of system. Out. println (), pay attention to the final brackets. What this function needs to do is when prompted.
"Add the right brackets
Function! My_bracketcomplete4omni ()
Let line = Getline ('.') "| example: line = system. ouout
Let dotpos = strridx (line, ".") "lengthof ('System. ')-1 Location of the last vertex.
Let cursepos = strlen (line) "lengthof ('System. ouout') cursor position
Let Len = cursepos-dotpos "lengthof (ouout) + 1 length between the cursor and the last Vertex
Let lastcharindex = strridx (line, '(') "to obtain the subscript of the last left brace and determine whether to add a right brace.
Let bedot = strpart (line, 0, dotpos) "part of the system before the last Vertex
Let afdot = strpart (line, dotpos + 1, Len) "part after the last point of ouout
Let B = match (afdot, '/(/W/+/)/1') "The begin index of ouou
Let E = matchend (afdot, '/(/W/+/)/1') "The end index of ouou
Let OK = strpart (afdot, (e-B)/2) "out, all the char after the first 'U' of ouout
"Debug
"Return repeat ("/<BS> ", len-1 ). OK. "/nline :". line. "/ndotpos :". dotpos. "/ncursepos :". cursepos. "/nlen :". len. "/nlastcharindex :". lastcharindex. "/nbedot :". bedot. "/nafdot :". afdot. "/NB :". b. "/ne :". e. "/NOK :". OK. "/nrep :". rep
Let rep = repeat ("/<left>", strlen (OK)-1) "Move strlen (OK) Forward length position, to delete the repeated ou at the beginning of ouout.
Let lenofok = strlen (OK)
Let lenofbetweendotandok = len-lenofok
Let rep = rep. Repeat ("/<BS>", lenOfBetweenDotAndOk-1) "deletes the repeated ou that appears before the ouout
Let rep = rep. Repeat ("/<right>", lenofok) "move the cursor backward to the original position
If lastcharindex =-1
If dotpos =-1
Return ""
Else
Return rep
Endif
Else
Return rep. ")/<left>"
Endif
Endfunction

Let G: closetag_html_style = 1
Autocmd filetype XML, html imap >>< C-_>
Autocmd filetype Python set omnifunc = pythoncomplete # complete
Autocmd filetype JavaScript set omnifunc = javascriptcomplete # completejs
Autocmd filetype HTML set omnifunc = htmlcomplete # completetags
Autocmd filetype CSS set omnifunc = csscomplete # completecss
Autocmd filetype XML set omnifunc = xmlcomplete # completetags
Autocmd filetype PHP set omnifunc = phpcomplete # completephp
Autocmd filetype C set omnifunc = ccomplete # complete
Autocmd filetype Java set omnifunc = javacomplete # complete
Autocmd filetype Java set completefunc = javacomplete # completeparamsinf

Autocmd filetype Java, JavaScript, HTML, css imap; <C-R> = my_appendsemicolon () <CR> <ESC>
Autocmd filetype Java, JavaScript, HTML, CSS map; I;
Autocmd filetype Java, JavaScript, html imap "" <CR> <ESC> Ka <ESC> XA <ESC> ppjhi
Autocmd filetype Java, JavaScript, HTML, vim imap ''<CR> <ESC> Ka <ESC> XA <ESC> ppji
Autocmd filetype Java, JavaScript inoremap <buffer>... <C-X> <C-O> <C-P>
Autocmd filetype CSS inoremap <buffer >:< C-X> <C-O> <C-P>
Autocmd filetype CSS, JavaScript, Java inoremap <buffer> <tab> <C-O>
Autocmd filetype JavaScript, CSS inoremap <buffer> <space> <C-X> <C-O> <C-P> <C-R> = my_bracketcomplete4omni () <CR>
Autocmd filetype Java, JavaScript, CSS, HTML, inoremap <buffer> <F2> <C-O> <C-X> <C-O> <C-P> = my_bracketcomplete4omni () <CR>
Autocmd filetype Java, JavaScript, CSS, HTML inoremap <buffer> <F3> <C-O> <C-X> <C-O> <C-P> <C-R> = my_bracketcomplete4omni () <CR>
Autocmd filetype Java, JavaScript, CSS, HTML inoremap <buffer> <F1> <C-O> <C-X> <C-O> <C-P> = my_bracketcomplete4omni () <CR>

Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> A <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> B <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> C <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> d <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> E <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> F <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> G <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> H <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> I <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> j <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> K <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> L <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> m <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> n <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> o <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> P <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> q <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> r <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> S <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> T <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> UU <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> v <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> W <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> x <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> Y <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> Z <C-N> <C-P>

Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> A <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> B <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> C <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> d <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> E <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> F <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> G <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> H <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> I <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> j <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> K <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> L <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> m <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> n <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> o <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> P <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> q <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> r <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> S <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> T <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> UU <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> v <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> W <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> x <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> Y <C-N> <C-P>
Autocmd filetype Java, JavaScript, CSS, HTML, XML inoremap <buffer> Z <C-N> <C-P>

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.