1

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?

pvd
  • 1,303
  • 2
  • 16
  • 31
  • No, slimv (actually paredit.vim) does not support java files. It only supports lisp-like files (lisp, clojure, scheme, racket). It is implemented for handling s-expressions. – Tamas Kovacs Feb 20 '13 at 09:44
  • @TamasKovacs Any advices for java programmer who uses vim as editor? – pvd Feb 20 '13 at 10:54
  • 1
    Sorry, I don't have any advice for java. I'm the author of slimv, so I can help you in slimv-related questions. What I can tell you is that you cannot use slimv for java files, because it checks for the presence of well-formed s-expressions. – Tamas Kovacs Feb 20 '13 at 11:51

2 Answers2

1

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.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Actually, my vimrc setting above was copied from the web site you suggested:) – pvd Feb 20 '13 at 09:28
  • Then have a look at the plugins section. I personally use AutoClose by Karl Guertin (rarely, but haven't noticed any issues with it yet). – Ingo Karkat Feb 20 '13 at 10:50
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.

Kirill
  • 406
  • 3
  • 11