Difference between revisions of "Vim"

From HaskellWiki
Jump to navigation Jump to search
(remove neco-ghc as it depends on deprecated ghc-mod, remove outdated link)
(Add haskell-vim)
Line 84: Line 84:
   
 
== List of Plugins ==
 
== List of Plugins ==
  +
* [https://github.com/neovimhaskell/haskell-vim haskell-vim]
 
  +
Quote from [https://blog.jez.io/haskell-development-with-neovim/]:
* [https://github.com/bitc/vim-hdevtools Hdevtools] taken from the github page:
 
 
<blockquote>
 
<blockquote>
  +
It’s the filetype plugin for Haskell that should ship with Vim.
hdevtools is a command line program powered by the GHC API, that provides services for Haskell development. hdevtools works by running a persistent process in the background, so that your Haskell modules remain in memory, instead of having to reload everything each time you change only one file. This is just like :reload in GHCi - with hdevtools you get the speed of GHCi as well as tight integration with your editor.
 
 
This is the Vim plugin that integrates Vim with hdevtools.
 
 
</blockquote>
 
</blockquote>
   
Line 97: Line 95:
 
</blockquote>
 
</blockquote>
 
Comes with linters cabal_ghc, ghc, ghc_mod, hdevtools, hie, hlint, stack_build, stack_ghc
 
Comes with linters cabal_ghc, ghc, ghc_mod, hdevtools, hie, hlint, stack_build, stack_ghc
  +
 
* [https://github.com/bitc/vim-hdevtools Hdevtools] taken from the github page:
  +
<blockquote>
 
hdevtools is a command line program powered by the GHC API, that provides services for Haskell development. hdevtools works by running a persistent process in the background, so that your Haskell modules remain in memory, instead of having to reload everything each time you change only one file. This is just like :reload in GHCi - with hdevtools you get the speed of GHCi as well as tight integration with your editor.
  +
 
This is the Vim plugin that integrates Vim with hdevtools.
  +
</blockquote>

Revision as of 19:39, 15 March 2019

This page is intended for Haskell vim-users.

Indentation

The following setup from merijn @ #haskell ensures you use spaces not tabs for indentation for generally sane behaviour:

" Tab specific option
set tabstop=8                   "A tab is 8 spaces
set expandtab                   "Always uses spaces instead of tabs
set softtabstop=4               "Insert 4 spaces when tab is pressed
set shiftwidth=4                "An indent is 4 spaces
set shiftround                  "Round indent to nearest shiftwidth multiple

Plugins

Put code in file ~/.vim/plugin/Haskell.vim, or in multiple files in that directory.

Module Sections

The following code prompts for a name, and places a section with that name at current position, when key sequence "--s":

let s:width = 80

function! HaskellModuleSection(...)
    let name = 0 < a:0 ? a:1 : inputdialog("Section name: ")

    return  repeat('-', s:width) . "\n"
    \       . "--  " . name . "\n"
    \       . "\n"

endfunction

nmap <silent> --s "=HaskellModuleSection()<CR>gp

Like so:

--------------------------------------------------------------------------------
--  my section


Module Headers

The following code prompts for module name, a note, a description of module, and places a module comment at top, when key sequence "--h":

let s:width = 80


function! HaskellModuleHeader(...)
    let name = 0 < a:0 ? a:1 : inputdialog("Module: ")
    let note = 1 < a:0 ? a:2 : inputdialog("Note: ")
    let description = 2 < a:0 ? a:3 : inputdialog("Describe this module: ")
    
    return  repeat('-', s:width) . "\n" 
    \       . "-- | \n" 
    \       . "-- Module      : " . name . "\n"
    \       . "-- Note        : " . note . "\n"
    \       . "-- \n"
    \       . "-- " . description . "\n"
    \       . "-- \n"
    \       . repeat('-', s:width) . "\n"
    \       . "\n"

endfunction


nmap <silent> --h "=HaskellModuleHeader()<CR>:0put =<CR>

like so:

--------------------------------------------------------------------------------
-- | 
-- Module      : MyModule
-- Note        : This is a preview
-- 
-- This is an empty module, to show the headercomment produced. 
-- 
--------------------------------------------------------------------------------

List of Plugins

Quote from [1]:

It’s the filetype plugin for Haskell that should ship with Vim.

  • Ale (Asynchronous Linting Engine)

ALE (Asynchronous Lint Engine) is a plugin for providing linting (checking syntax and semantics) in NeoVim 0.2.0+ and Vim 8 while you edit your text files, and acts as a Vim Language Server Protocol client.

Comes with linters cabal_ghc, ghc, ghc_mod, hdevtools, hie, hlint, stack_build, stack_ghc

hdevtools is a command line program powered by the GHC API, that provides services for Haskell development. hdevtools works by running a persistent process in the background, so that your Haskell modules remain in memory, instead of having to reload everything each time you change only one file. This is just like :reload in GHCi - with hdevtools you get the speed of GHCi as well as tight integration with your editor.

This is the Vim plugin that integrates Vim with hdevtools.