How to have VIM show unclosed parenthesis?

9

0

Is there a way that I can change my .vimrc file so that unclosed parenthesis/brackets/braces are highlighted? For instance the following would highlight the parenthesis after the word main:

public static void main(String[] args
{
    System.out.println("Foobar");
}

Or perhaps, have VIM somehow tell me that I have an unclosed parenthesis. It appears that VIM currently shows when you have an unopened parenthesis but not when you have an unclosed one.

Nosrettap

Posted 2013-02-01T21:53:05.140

Reputation: 711

This would be nice, though I doubt we will see a solution since the default would be the same next close peren, so the missing one after String[] would be assumed as the one after since VIM doesn't know that's not an argument. – nerdwaller – 2013-02-02T01:35:27.580

Answers

2

There exists a plugin for vim to do just this. Given this your example code:

public static void main(String[] args
{
    System.out.println("Foobar");
}

Wherever you place your cursor, the closest back mismatched parentheses will be highlighted. The only defect is that it doesn't look ahead, to see if it is matched later. So if you were within the pringln parentheses if would highlight the opening one. It is basically functional and should serve you fine.

It is called vim-matchopen and can be found at https://github.com/arnar/vim-matchopen


If you havn't had expirence installing vim plugins, here is a quick intro for this one. (I am assuming that you are using Linux.)

Go to the download site. If you have git and know how to use it, go ahead. If not then use the download zip button, and extract the downloaded zip to some temporary destination.

Next you need to take the script plugin/matchopen.vim and place it in the directory ~/.vim/plugin. If that directory doesn't exist, create it.

That should be it. Then you will be up and running. Just restart vim.

Sudo Bash

Posted 2013-02-01T21:53:05.140

Reputation: 93