Created
August 27, 2015 16:25
-
-
Save qstrahl/53c5d6c450b9d92198ac to your computer and use it in GitHub Desktop.
Make gq format your javascript with js-beautify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"" This file goes in after/indent/javascript.vim | |
function! MyJavascriptFormatter (lnum, count) | |
if mode() == 'i' | |
return 1 | |
elseif synIDattr(synIDtrans(synID(line('.'), col('.'), 0)), 'name') == 'Comment' | |
return 1 | |
endif | |
let l:options = [] | |
let l:options += [ &expandtab ? '-s ' . &shiftwidth : '-t' ] | |
let l:options += [ '-w ' . &textwidth ] | |
let l:options += [ '-q' ] | |
let l:options += [ '-f -' ] | |
silent exe a:lnum . ',+' . (a:count - 1) . '!js-beautify ' . join(l:options, ' ') | |
undojoin | silent exe "'[,']retab!" | |
endfunction | |
if executable('js-beautify') | |
setlocal formatexpr=MyJavascriptFormatter(v:lnum,v:count) | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment