Search code examples
vim

Make Vim Curly Braces, Square Braces, Parens act like Textmate


So I guess I'm not searching for the right thing but I'm looking to see how you can get VIM to act like Textmate when it comes to writing a set of curly braces, parens, or square brackets hit enter and you get this. Pipe indicates cursor.

      function doSomething(){
          |
      }

      #selector{
          |
      }

Instead of this garbage

      function doSomething(){
      |}

      #selector{
      |}

I already have the [{( closing each other when they are typed just the return and indentation is jacked. As usual any help would be appreciated.


Solution

  • I use the following mappings in my .vimrc:

    inoremap {<cr> {<cr>}<c-o>O<tab>
    inoremap [<cr> [<cr>]<c-o>O<tab>
    inoremap (<cr> (<cr>)<c-o>O<tab>
    

    So when I input:

    function foo(){<cr>
    

    I get:

    function foo(){
        |
    }
    

    Similar with (<cr> and [<cr>.