Search code examples
vimhaskelltabsliterate-programming

Infuriating Tab problem in Vim, in literate Haskell


I am using "Bird" style literate haskell, which requires all code to be like the following:

> module Main (main) where

and if I have a block it should look something like this:

> main = do
>     args = getArgs
>     file = args!![0]

etc. However when I enter the gt sign, then a space and hit tab it tabs over only two spaces!

I have done the following to try to fix the problem:

set tabexpand
set tabstop=4
set softtabstop=4
set noautoindent
set shiftwidth=4

Any help would be much appreciated I thought the above would essentially just make it insert 4 spaces rather than any tabs.


Solution

  • I don't know any easy way to solve this, but here are some workarounds you can try (in rough order of complexity).

    1. Set your indentation to two spaces and live with having to press tab twice.

    2. Make tab indiscriminately insert 4 spaces in insert mode, ignoring all tab stop and indentation rules/options.

      :imap <Tab> <Space><Space><Space><Space> 
      
    3. Use a patched Vim which allows you to set arbitrary tabstops. There's a variable tabstops patch at the Vim patches page.

    4. Write your own indentation algorithm. See :help indentexpr for details on how to do this.