[Haskell-cafe] (automatically) adding import statements in vim

cdep.illabout at gmail.com cdep.illabout at gmail.com
Wed Dec 25 11:45:12 UTC 2013


Are there any tools or vim-plugins that will automatically add
 import statements?

For instance, I have the following code:

...
import Data.Maybe (fromJust)
import Text.ParserCombinators.Parsec (ParseError)
import Text.Printf (printf)
...

parseMyString :: String -> Either ParseError String
parseMyString stringToParse = parse myParser "(unknown)" stringToParse


Here's what I want to have happen.  I put my cursor over "parse" and
press some keystroke.  It automatically adds the parse function to the
list of import statements from the Text.ParserCombinators.Parsec
module (hopefully sorted alphabetically).  So the import statements
end up looking like this:

...
 import Data.Maybe (fromJust)
import Text.ParserCombinators.Parsec (ParseError, parse)
import Text.Printf (printf)
...

The haskellmode vim plugin
(https://github.com/lukerandall/haskellmode-vim) has functionality
similar to this, but it can only add new import lines.  It can't add
functions/types to existing import lines.

The best it can do is something like this:

...
 import Data.Maybe (fromJust)
import Text.ParserCombinators.Parsec (ParseError)
import Text.Printf (printf)
import Text.ParserCombinators.Parsec (parse)
...

This is alright, but I have to go back and edit it by hand to make it
look like the above.

Are there any tools or vim-plugins that can do this automatically?


More information about the Haskell-Cafe mailing list