So I am trying out javascript on vim. It is great that it automatically indents the braces for me when I close them etc.. But I was typing some JS and got into a bracket muddle. Here is what I had:

angular.module('functionalities', [])
.directive("entering", function() {_}

I have put an underscore to represent where my cursor was when I started typing, in this case it was on this line in between the two braces : .directive("entering", function() {_}

when I press enter the closing brace stays behind my cursor, is there a way to get it to go to the line underneath my cursor and indent correctly? like this:

angular.module('functionalities', [])
.directive("entering", function() {

When I close braces, it automatically indents them in the right place for me, I am not sure if this due to a plugin I may have installed like Surround.vim but in this kind of situation where I insert text before the brace, it put me into a muddle with my brackets.

Suggestions would be incredibly appreciated.

  • 1
    Are autoindent and cindent on? Try setting them on, maybe that will help? – user10607 Jul 11 '15 at 14:47
  • 2
    Ok here is a hack in your vimrc add: inoremap { {<CR>}<C-o>O this means that every time in insert mode when you hit { vim will put a {, press Enter, put the closing } and open at line above it. So....... actually instead of using the hack you can just train your fingers to hit shift + O after you hit enter. – user10607 Jul 11 '15 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.