Vim smart insert semicolon

前端 未结 7 828
遇见更好的自我
遇见更好的自我 2021-02-04 00:49

Is there a Vim plugin that can handle smart semicolon insertion, like the one in Eclipse?

Example (pipe character is insertion cursor):

foobar(|)
         


        
相关标签:
7条回答
  • 2021-02-04 01:35
    " ftplugin/c/c_snippet.vim
    inoremap <expr> <buffer> ; getline('.')[col('.')-1:-1]=~')$' ? '<right>;' : ';'
    

    This version shall not pose problems with for if your snippets engine expands it into

    for (...|) {
       <+code+>
    }<++>
    

    If the open bracket is on a newline, it will mess things up.

    You could easily change the regex to '"\=)\+$' to answer your initial question.

    inoremap <expr> <buffer> ; getline('.')[col('.')-1:-1]=~'"\=)\+$' ? '<end>;' : ';'
    

    However, I don't think it's a good idea. In that case, the mapping for <bs>will be:

    inoremap <expr> <buffer> <bs> getline('.')[:col('.')-2] =~ '.*")\+;$' ? '<bs><c-o>F";' : '<bs>'
    
    0 讨论(0)
提交回复
热议问题