Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Beautify your javascript,html,css source code inside Vim

branch: master
README.md

sourcebeautify.vim

Beautify your source code in Vim

It support javascript,css,html which is powered by js-beautify and JSON powered by jsonlint

More language support is well welcomed, your can develop it by pure javascript, see Customization for more info.

Install

This plugin requires jsruntime.vim and jsoncodecs.vim to be installed first

then copy plugin/sourcebeautify to vimfiles/plugin

Sourcebeautify support json file, but vim can't detect json type automaticly. You can add following code to your vimrc. I suggest to install json.vim

au BufRead,BufNewFile *.json setf json

Usage

<Leader>sb

Your <Leader> key is often \

Customization

  1. jsbeautify options

    Take a look at beautify-css.run.js, this file contains following code

    css_beautify(%s);
    

    %s refers to the codes before beautify, the other part is pure javascript, for example

    css_beautify(%s,{indent_char:'\t'});
    

    javascript beautifier options, html beautifier options, css beautifier options, jsonlint options

  2. add more language support

    If you wants this plugin to support cpp file, you should create beautify-cpp.js and beautify-cpp.run.js.

    These two files should be written by pure javascript, then modify sourcebeautify.vim add declaration and alias

    " sourcetype that support by this plugin
    let s:beautifiers.supportedSourceType={
    \'javascript':1,
    \'css':1,
    \'html':1
    \}
    
    " sourcetype name alias
    let s:beautifiers.supportedSourceTypeAlias={
    \'javascript':['js'],
    \'html':['xhtml','htm']
    \}
    

Contributor

Einar Lielmanis - author of js-beautify provide beautifier of javascript,html,css file

Zach Carter - author of jsonlint provide error checker and beautifier of JSON file

Something went wrong with that request. Please try again.