5

When I turn on autoindent for a regular *.hs file, the after pressing Enter the new line is indented as expected. However, this doesn't work with literate Haskell *.lhs files whose code lines start with > (AKA "bird-tracks"). The cursor is always positioned at the first column.

How can I set up vim so that when I'm inside a piece of code in a *.lhs file (and let\s say have autoindent on), pressing Enter creates a bird track at the new line and indents appropriately?

Update: To give an example, let's say have

> myfn x | x <= 0     = 0
>        | x == 1     = 1▌

where represents the position of the cursor (I hope you have no problem seeing the unicode character.) If I press Enter, I end up with

> myfn x | x <= 0     = 0
>        | x == 1     = 1
▌

whereas I want

> myfn x | x <= 0     = 0
>        | x == 1     = 1
>        ▌
Petr
  • 62,528
  • 13
  • 153
  • 317

1 Answers1

7

This should be easy to achieve with

:set formatoptions+=ro

or :se fo+=ro for short.

With r and o in 'formatoptions', Vim attempts to insert the comment "leader" including indentation on new lines inside a comment (that is, a non-comment in literate Haskell).

To make this setting automatically, set up an autocommand in your vimrc.

autocmd FileType lhaskell setlocal formatoptions+=ro

Tip: Use CTRL-U to remove the auto-inserted leader when you don't need it.

glts
  • 21,808
  • 12
  • 73
  • 94
  • Unfortunately this doesn't work. Apparently, the code blocks starting with `> ` aren't treated as comments, so `ro` doesn't apply to them (I already have those flags on, I have `tcroql`). – Petr Sep 02 '13 at 11:57
  • @PetrPudlák Oh, it does work! Check if the `lhaskell` filetype is correctly recognized `:set ft?`. – glts Sep 02 '13 at 12:04
  • @PetrPudlák I imagine you have a plugin that interferes with things. Anyway, you can try `:set comments+=:>` to make the `>` a comment leader. – glts Sep 02 '13 at 12:15
  • You're right, I tried it on another machine and it works. So I'll have to go through the plugins and find out which one is causing the trouble. – Petr Sep 02 '13 at 12:22
  • It was caused by _haskellmode_ plugin. After uninstalling it, it works. – Petr Sep 02 '13 at 12:37