Ⅰ. 插件描述
Beautify your javascript,html,css source code inside VimⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'michalliu/sourcebeautify-vim'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'michalliu/sourcebeautify-vim'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'michalliu/sourcebeautify-vim'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/michalliu/sourcebeautify.vim
Ⅳ. 文档说明
sourcebeautify.vim
Beautify your source code in Vim. It supports Windows/Linux/Mac up to vim 8.0
Language support:
- [x] Javascript,CSS,HTML by js-beautify
- [x] JSON by jsonlint
- [x] XML,SQL by vkBeautify
More language support is well welcomed, your can develop it by pure javascript, see Customization section for more info.
Installation
First, Install dependencies:
Then, Copy plugin/sourcebeautify to vimfiles/plugin
Notice:
Sourcebeautify is a filetype plugin. By default VIM can't detect json filetype automaticly. You can either add following code to your vimrc to solve the problem or install json.vim
au BufRead,BufNewFile *.json setf json
Usage
<Leader>sb
Your <Leader> key is often \
Customization
jsbeautify options
Take a look at `beautify-css.run.js`, this file contains following codecss_beautify(%s);
`%s` refers to the codes before beautify, the other part is pure javascript, for examplecss_beautify(%s,{indent_char:'t'});
[javascript beautifier options](https://github.com/beautify-web/js-beautify/blob/v0.4.2/beautify.js), [html beautifier options](https://github.com/beautify-web/js-beautify/blob/v0.4.2/beautify-html.js), [css beautifier options](https://github.com/beautify-web/js-beautify/blob/v0.4.2/beautify-css.js), [jsonlint options](https://github.com/zaach/jsonlint)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']
}
Contributors
- Einar Lielmanis - author of js-beautify provides beautifier of
javascript,html,cssfile - Zach Carter - author of jsonlint provides error checker and beautifier of
JSONfile - Vadim Kiryukhin - author of vkBeautify provides XML and SQL beautifier