Skip to content

Instantly share code, notes, and snippets.

@OscarGodson
Created May 30, 2013 19:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save OscarGodson/5680434 to your computer and use it in GitHub Desktop.
Save OscarGodson/5680434 to your computer and use it in GitHub Desktop.

Example output, where | is the cursor:

function () {
  |
};
foo(function () {
  |
});
if () {
  |
}

Along with else, for, and switch.

Also does this correctly:

var x = {
  foo: function () {
    |
  } // No semi!
}; // Semi!
fun! SemiOrNoSemi()
return "{\<cr>}\<c-o>O\<Tab>\<Down>".(getline('.') =~# '^\s*for\s\|if\s\|else\s|switch\s'||getline('.') =~# ':'? '' : ';')."\<up>"
endfunction
au BufNewFile,BufRead *.js imap <buffer> <expr> {<cr> SemiOrNoSemi()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment