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
> ▌
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With