2012-09-30 16:09:46 -04:00
|
|
|
vim-autoformat
|
2012-12-01 05:18:53 -05:00
|
|
|
==============
|
2013-01-21 07:34:25 -05:00
|
|
|
Format your code with only one button press!
|
2013-02-09 10:27:20 -05:00
|
|
|
This plugin makes use of external formatprograms to achieve the best result.
|
2013-01-21 07:34:25 -05:00
|
|
|
Check the list of formatprograms to see which languages are currently supported.
|
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
|
|
|
|
----------
|
2012-12-06 17:58:01 -05:00
|
|
|
First you have to install an external program that can format code of the programming language you are using.
|
2012-12-11 12:34:49 -05:00
|
|
|
It suffices to make the formatprogram either globally available
|
|
|
|
(which is the case if you installed it via your package manager)
|
|
|
|
or to put it in the `formatters/` folder.
|
2012-12-02 15:28:27 -05:00
|
|
|
Sometimes alternative installation methods are supported.
|
2012-12-02 09:12:04 -05:00
|
|
|
|
2012-12-03 03:03:07 -05:00
|
|
|
When you have installed the formatters you need, you can format the 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:
|
2012-12-02 15:19:14 -05:00
|
|
|
|
2012-12-02 09:12:04 -05:00
|
|
|
```vim
|
2012-12-03 03:03:07 -05:00
|
|
|
noremap <F7> :Autoformat<CR><CR>
|
2012-12-02 09:12:04 -05:00
|
|
|
```
|
|
|
|
|
2012-12-06 17:58:01 -05:00
|
|
|
If you don't want to format the whole vimbuffer, you can alternatively format visually selected code with `gq`.
|
2012-12-02 15:36:06 -05:00
|
|
|
For more ways to perform autoformatting type `:help gq`.
|
2012-12-02 09:12:04 -05:00
|
|
|
|
2012-12-01 15:34:44 -05:00
|
|
|
Supported formatprograms
|
|
|
|
------------------------
|
2012-12-15 07:56:15 -05:00
|
|
|
With most of the distro's, if you installed a formatprogram, it's automatically globally available.
|
|
|
|
If this is not the case, you can either make it globally available manually, or put it's binary in the `formatters/` directory.
|
|
|
|
Sometimes alternative installation methods are presented.
|
2012-12-02 13:55:32 -05:00
|
|
|
Here is a list of formatprograms that are currently supported.
|
2012-12-06 17:58:01 -05:00
|
|
|
|
2013-02-09 10:28:20 -05:00
|
|
|
* `astyle` for __C#__, __C++__, __C__ and __Java__.
|
2012-12-15 07:56:15 -05:00
|
|
|
It's probably in your distro's repository, so you can download it as a regular package.
|
2012-12-06 17:58:01 -05:00
|
|
|
For Ubuntu type `sudo apt-get install astyle` in a terminal.
|
2013-02-08 16:46:20 -05:00
|
|
|
Otherwise, download it here: http://astyle.sourceforge.net/.
|
2012-12-02 14:54:59 -05:00
|
|
|
|
2012-12-15 07:56:15 -05:00
|
|
|
* `jsbeautify` (the python CLI version) for __Javascript__.
|
|
|
|
This one can also be installed as a vundle package, and I recommend to do so.
|
|
|
|
Put this in your .vimrc: `Bundle "einars/jsbeautify"`.
|
2012-12-06 17:58:01 -05:00
|
|
|
Note that we're only using the python version, so `node` doesn't have to be installed.
|
2013-02-08 16:46:20 -05:00
|
|
|
Here is the link to the repository: https://github.com/einars/js-beautify.
|
2012-12-06 17:50:38 -05:00
|
|
|
|
2012-12-02 15:19:14 -05:00
|
|
|
* `autopep8` for __Python__.
|
2012-12-15 07:56:15 -05:00
|
|
|
It's probably in your distro's repository, so you can download it as a regular package.
|
2012-12-06 17:58:01 -05:00
|
|
|
For Ubuntu type `sudo apt-get install autopep8` in a terminal.
|
2013-02-08 16:46:20 -05:00
|
|
|
Here is the link to the repository: https://github.com/hhatto/autopep8.
|
|
|
|
And here the link to its page on the python website: http://pypi.python.org/pypi/autopep8/0.5.2.
|
2012-12-06 17:50:38 -05:00
|
|
|
|
|
|
|
* `phpCB` for __PHP__.
|
2013-02-08 16:46:20 -05:00
|
|
|
You can download it's binary here:
|
|
|
|
http://www.waterproof.fr/products/phpCodeBeautifier/download.php.
|
2012-12-06 17:50:38 -05:00
|
|
|
I recommend putting the phpCB binary in the `formatters/` directory.
|
2012-12-01 15:34:44 -05:00
|
|
|
|
2013-02-09 10:28:20 -05:00
|
|
|
* `tidy` for __HTML__ and __XML__.
|
2013-01-20 12:56:32 -05:00
|
|
|
It's probably in your distro's repository, so you can download it as a regular package.
|
|
|
|
For Ubuntu type `sudo apt-get install tidy` in a terminal.
|
|
|
|
|
2012-12-02 15:19:14 -05:00
|
|
|
If you find yourself in need of support for another formatprogram, simply add a configuration file in the folder `vim-autoformat/ftplugin/`.
|
2012-12-01 15:34:44 -05:00
|
|
|
You can take the existing ones as an example.
|
2013-02-08 16:46:20 -05:00
|
|
|
Be sure to send me a patch. :)
|
2012-12-02 15:15:45 -05:00
|
|
|
|
|
|
|
How can I change the behaviour of formatters?
|
|
|
|
---------------------------------------------
|
2012-12-02 15:19:14 -05:00
|
|
|
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`.
|
2012-12-02 15:36:06 -05:00
|
|
|
You can change the arguments passed to the formatter in that file.
|
2012-12-03 15:37:30 -05:00
|
|
|
|
2013-01-20 12:56:32 -05:00
|
|
|
Todo list
|
|
|
|
---------
|
|
|
|
* Check for windows support.
|
2013-01-22 14:49:39 -05:00
|
|
|
|
|
|
|
|
2013-02-08 16:46:20 -05:00
|
|
|
If you have any suggestions on this plugin or on this readme or if you experience problems, please contact me by creating an issue in this repository.
|