Hacker News new | ask | show | jobs
by coliveira 6522 days ago
use :set showmatch
1 comments

Showmatch is there to highlight matching braces, not to insert them. The mappings actually match your braces by writing the close brace/parens/bracket. Here are the coding aids from my vimrc. They're pretty simple, as I don't like to change how Vim works too much:

  " Coding aids
  set undolevels=5000
  set backspace=indent,eol,start
  vnoremap < <gv
  vnoremap > >gv
  " Braces, etc.
  inoremap ( ()<LEFT>
  inoremap (<CR> (<CR>)<ESC>O
  inoremap () ()
  inoremap { {}<LEFT>
  inoremap {<CR> {<CR>}<Esc>O
  inoremap {{ {
  inoremap [ []<LEFT>
  inoremap [<CR> [<CR>]<Esc>O
  inoremap [] []
  " Wrap in braces, etc.
  vnoremap -( <ESC>`>a)<ESC>`<i(<ESC>
  vnoremap -[ <ESC>`>a]<ESC>`<i[<ESC>
  vnoremap -{ <ESC>`>a}<ESC>`<i{<ESC>
  vnoremap -" <ESC>`>a"<ESC>`<i"<ESC>
  vnoremap -' <ESC>`>a'<ESC>`<i'<ESC>
  " End the line, adding a semicolon
  inoremap <S-CR> <ESC>A;<ESC>o
  noremap <S-CR> A;<ESC>j

I also use NERDCommenter for quick commenting, an XML tag wrapper script, and a tag closer script. As you can see above, typing the open/close pair doesn't result in "())", and typing an open brace plus a carriage return automatically adds the close brace to the line below, in the format:

  function hello($name) {
      // Insertion point
  }
Edit: Of course, that isn't my entire .vimrc