vim:Can braces auto complete in java file as elegant as lisp file with slimv?

☆樱花仙子☆ 提交于 2019-12-11 09:00:59

问题


I have been use slimv for a long time, and found it's great in braces auto complete.

However, while I was editing java file, I tried to add this code in my vimrc

"Add the closing brace only at the end of the line
function! ConditionalPairMap(open, close)
  let line = getline('.')
  let col = col('.')
  if col < col('$') || stridx(line, a:close, col + 1) != -1
    return a:open
  else
    return a:open . a:close . repeat("\<left>", len(a:close))
  endif
endf
inoremap <expr> ( ConditionalPairMap('(', ')')
inoremap <expr> { ConditionalPairMap('{', '}')
inoremap <expr> [ ConditionalPairMap('[', ']')

Which is not smart as slimv does.

Is slimv support for java files?


回答1:


Try Vim-autoclose. Possibly will work for Java.

I've been using it for a while now. It's works perfectly for PHP & JS. Only occasional problem when pasting code in. But easily solved by deleting a bunch of closing brackets at the end of the file.




回答2:


There are a couple of plugins that provide auto-closing of braces and are probably more robust than your simplistic mapping. See the topic Automatically append closing characters on the Vim Tips Wiki for a discussion and list of plugins.



来源:https://stackoverflow.com/questions/14974738/vimcan-braces-auto-complete-in-java-file-as-elegant-as-lisp-file-with-slimv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!