Skip to content

Instantly share code, notes, and snippets.

@brendanjerwin
Created February 21, 2012 00:03
Show Gist options
  • Save brendanjerwin/1872435 to your computer and use it in GitHub Desktop.
Save brendanjerwin/1872435 to your computer and use it in GitHub Desktop.
Source this in your .vimrc
function! CoffeeClean()
let save_cursor = getpos(".")
"general puncuation spacing cleanup
"
"Missing spaces
silent! %s/\v','/', '/g
silent! %s/\v","/", "/g
silent! %s/\v:(\w)(['"].*)@<!/: \1/g
silent! %s/\v:\@(['"].*)@<!/: @/g
"ensure space after =
silent! %s/\v\=(\S)/= \1/g
"Extra spaces
silent! %s/\v\s+\=\s+/ = /g
silent! %s/\v(\w)\s+,/\1,/g
"use single quotes for 'normal' strings, leave double quotes for
"interpolated strings
" silent! %s/"\([^#"']\+\)"/'\1'/g
silent! %s/""/''/g
"remove extra spaces around braces
silent! %s/ ]/]/g
silent! %s/\[ /[/g
silent! %s/( /(/g
silent! %s/\v(\S)\s+\)/\1)/g
silent! %s/\(\w\) )/\1)/g
"lambdas
"
"always remove a space before the rocket
silent! %s/) ->/)->/g
silent! %s/) =>/)=>/g
"cleanup lambdas as contained in parens. ensure a space to make it stand
"out
silent! %s/\v\(\((\w+)\)-\>/( (\1)->/g
silent! %s/\v\(\((\w+)\)=\>/( (\1)=>/g
"a parameterless lambda should always have a space in front
silent! %s/\v:-\>/: ->/g
silent! %s/\v:\=\>/: =>/g
"simple cleanups for common stuff
silent! %s/'use strict';/'use strict'/g
silent! %s/@$/this/
call setpos('.', save_cursor)
endfunction
autocmd BufWritePre *.coffee call CoffeeClean()
@brendanjerwin
Copy link
Author

brendanjerwin commented Feb 21, 2012 via email

@JamesMaroney
Copy link

JamesMaroney commented Feb 21, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment