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

StackOverflow https://stackoverflow.com/questions/14974738

  •  10-03-2022
  •  | 
  •  

Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top