This is just a modified version of the vim-hindent plugin that supports range selection.
Integrates with hindent so every time you save a Haskell source file it gets automatically prettified.
Simply using :%!hindent replaces your whole source file with an error message
from hindent when you happen to have a syntax error in your code, this
plugin manages that annoyance.
Note: If you prefer stylish-haskell use vim-stylishask instead.
Compatible with Vundle, Pathogen, Vim-plug.
By default, vim-hindent will format your code automatically when saving a
Haskell source file, but you can use the :Hindent command at any time to
format the current file.
Use :HindentEnable, :HindentDisable, :HindentToggle to enable, disable, or
toggle running hindent on save.
Trigger hindent when saving (default = 1):
g:hindent_on_save = 1Number of spaces per indentation (default = '', uses hindent default of 2):
g:hindent_indent_size = 2Max line length (default = '', uses hindent default of 80):
g:hindent_line_length = 100I personally prefer to disable formatting on save, therefore
g:hindent_on_save = 0Then I integrated some useful filetype specific mappings:
The first one uses vim-textobj-haskell to select the top level binding on which the cursor currently is, and then calls Hindent to format just that code fraction (the selection gives an helpful visually clue of whats going on)
autocmd FileType haskell map == vih:call hindent#Hindent()<CR>The second one is similar, but it does not use text objects. Instead it formats the whole file by not passing any range to the function. The empty range is treated as a whole-file selection by the plugin
autocmd FileType haskell map =G :call hindent#Hindent()<CR>