Ok. figured it out by looking into haskell.vim, I found ad slight modification of indentexpr would work.
check it out.
first,
$ cd ~/.vim/bundle/haskell-vim/
$ vi indent/haskell.vim
then find the definition of GetHaskellIndent function.
I add following lines right after the handling of -- comment, therefore the function becomes:
function! GetHaskellIndent()
let l:prevline = getline(v:lnum - 1)
if l:prevline =~ '^\s*--'
return match(l:prevline, '\S')
endif
if synIDattr(synID(line("."), col("."), 1), "name") == 'hsBlockComment'
for l:c in range(v:lnum - 1, 0, -1)
let l:bline = getline(l:c)
if l:bline =~ '{-'
return 1 + match(l:bline, '{-')
endfor
return 1
endif
starting from if synIDattr(synID(line("."), ... is my code.
basically what it means is check whether the current position is in block comment syntax, if so, get in the for loop and find the first occurrence of {-, then return the indent as deep as the - in {-.
notice that, my haskell environment is heavily customized. you should config according to yours. though my indent is setup to use haskell.vim, my syntax highlight is setup to use vim2hs. so it's better to look into the syntax highlight file first to find out what syntax element you should look at(in vim2hs's case, it should be 'hsBlockComment', in haskell.vim it should be 'haskellBlockComment').
after having this code, I have following effect:
{-
-
-
- -}
for comments in deep indent:
{-
-
-
-
-
- -}
works like a charm.
-s aligned. – Jason Hu Aug 17 '15 at 14:23cindentenabled on your system? (you can check with:set cindent?it will outputcindentornocindent) If it is enabled try disabling it with:set nocindentand see if it solves the problem. – statox Aug 17 '15 at 14:39cindentis not on indeed. but why would i needcindenton in haskell anyway? willcindentcorrupt the indent config set up by other plugins? – Jason Hu Aug 17 '15 at 15:04setlocal comments=s1fl:{-,mb:-,ex:-\ -},:--. @statox's answer didn't align for me either even though:h format-commentsseems to imply it should, but the modified original comments string aligns correctly – Jaymon Jan 26 '18 at 23:41