Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top