2012-09-30 16:09:46 -04:00
|
|
|
vim-autoformat
|
2012-12-01 05:18:53 -05:00
|
|
|
==============
|
2012-12-02 13:55:32 -05:00
|
|
|
This vim plugin integrates external code-formatting programs into vim automatically.
|
|
|
|
If you have installed a supported formatprogram correctly, you can use it within vim immediately.
|
|
|
|
You don't have to configure anything.
|
|
|
|
It works out of the box.
|
2012-12-01 13:03:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
How to install (Vundle)
|
|
|
|
-----------------------
|
|
|
|
Put this in your .vimrc
|
|
|
|
|
|
|
|
```vim
|
|
|
|
Bundle "Chiel92/vim-autoformat"
|
|
|
|
```
|
|
|
|
|
2012-12-02 09:12:04 -05:00
|
|
|
How to use
|
|
|
|
----------
|
|
|
|
To be able to use automatic code formatting, you have to install an external program that can format code of the programming language you are using.
|
2012-12-02 13:55:32 -05:00
|
|
|
Normally, it suffices to make the formatprogram either globally available or to put it in the ```formatters``` folder.
|
|
|
|
In some cases this is inconvenient to accomplish and therefore sometimes alternative installation methods are supported.
|
|
|
|
It is said explicitly if this is the case.
|
2012-12-02 09:12:04 -05:00
|
|
|
|
2012-12-02 13:55:32 -05:00
|
|
|
When you have succeed installing the formatters you need, you can format visually selected code with ```gq```.
|
2012-12-02 09:12:04 -05:00
|
|
|
For more info type ```:help gq```.
|
2012-12-02 13:55:32 -05:00
|
|
|
You can also format the whole buffer with the command ```:Autoformat```.
|
2012-12-02 09:12:04 -05:00
|
|
|
For convenience it is recommended that you assign a key for this, like so:
|
|
|
|
```vim
|
2012-12-02 13:55:32 -05:00
|
|
|
noremap <F7> :Autoformat<CR>
|
2012-12-02 09:12:04 -05:00
|
|
|
```
|
|
|
|
|
|
|
|
|
2012-12-01 15:34:44 -05:00
|
|
|
Supported formatprograms
|
|
|
|
------------------------
|
2012-12-02 13:55:32 -05:00
|
|
|
Here is a list of formatprograms that are currently supported.
|
2012-12-02 14:59:14 -05:00
|
|
|
* ```astyle``` for __C#, C++, C and Java__.
|
2012-12-02 14:54:59 -05:00
|
|
|
It's probably in your distro's repository, so you can download it as a regular package.
|
|
|
|
|
2012-12-02 14:59:14 -05:00
|
|
|
* ```jsbeautify``` (the python version) for __Javascript__.
|
2012-12-02 14:54:59 -05:00
|
|
|
This one can also installed as a vundle package (if you use the vundle plugin).
|
2012-12-02 13:58:45 -05:00
|
|
|
To do so, put this in your .vimrc:
|
2012-12-02 13:59:47 -05:00
|
|
|
|
2012-12-02 13:58:45 -05:00
|
|
|
```vim
|
|
|
|
Bundle "einars/jsbeautify"
|
|
|
|
```
|
2012-12-02 13:59:47 -05:00
|
|
|
|
2012-12-02 14:59:14 -05:00
|
|
|
* ```autopep8``` for __Python__.
|
2012-12-02 14:54:59 -05:00
|
|
|
It's probably in your distro's repository, so you can download it as a regular package.
|
2012-12-01 15:34:44 -05:00
|
|
|
|
|
|
|
If you find yourself in need of support for another formatprogram, simply add a configuration file in the folder ```ftplugin```.
|
|
|
|
You can take the existing ones as an example.
|
|
|
|
Oh, and be sure to send me a patch. :)
|
2012-12-02 15:15:45 -05:00
|
|
|
|
|
|
|
How can I change the behaviour of formatters?
|
|
|
|
---------------------------------------------
|
|
|
|
Every formatter is called from a script in the *vim-autoformat/ftplugin/* directory.
|
|
|
|
E.g. the file that calls the C# formatter is named *vim-autoformat/ftplugin/cs.vim*.
|
|
|
|
You can change the arguments passed to the formatter there.
|