Difference between revisions of "Vim"

From HaskellWiki
Jump to navigation Jump to search
 
(27 intermediate revisions by 9 users not shown)
Line 1: Line 1:
 
[[Category:Development tools]]
 
[[Category:Development tools]]
This page intended Haskell vim-users.
 
   
  +
There is a wide range of tools and corresponding VIM plugins that provide IDE-like features for Haskell development: [[haskell-language-server]] (implements the Language Server Protocol, thus needs a VIM LSP client), Intero, Dante, Codex, hdevtools and more. A less feature-rich but stable solution is to have ghcid running next to the editor window as described in [https://www.parsonsmatt.org/2018/05/19/ghcid_for_the_win.html]
= Indentation =
 
   
  +
== Haskell Language Server ==
The following setup from merijn @ #haskell ensures you use spaces not tabs for indentation for generally sane behaviour:
 
  +
If you want to use the [[Haskell Language Server]] with Vim or Neovim, there are sections in the docs for that:
   
  +
* [https://haskell-language-server.readthedocs.io/en/latest/configuration.html#neovim Using haskell-language-server with NeoVim].
<pre>
 
" 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 smarttab "Indent instead of tab at start of line
 
set shiftround "Round spaces to nearest shiftwidth multiple
 
set nojoinspaces "Don't convert spaces to tabs
 
</pre>
 
   
  +
* [https://haskell-language-server.readthedocs.io/en/latest/configuration.html#vim Using haskell-language-server with Vim].
= Plugins =
 
Put code in file <code>~/.vim/plugin/Haskell.vim</code>, 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":
 
<pre>
 
let s:width = 80
 
   
  +
== Assorted plugins for Vim or NeoVim ==
function! HaskellModuleSection(...)
 
let name = 0 < a:0 ? a:1 : inputdialog("Section name: ")
 
   
  +
* [https://github.com/MrcJkb/haskell-tools.nvim haskell-tools.nvim] Neovim plugin that sets up [https://neovim.io/doc/user/lsp Neovim's native LSP implementation] to use haskell-language-server and provides various other Neovim tools for Haskell development. Aims to bring the Haskell experience in Neovim on par and beyond that of Visual Studio Code.
return repeat('-', s:width) . "\n"
 
\ . "-- " . name . "\n"
 
\ . "\n"
 
   
  +
* [https://github.com/neoclide/coc.nvim coc.nvim] Intellisense engine for Vim8 & Neovim, full language server protocol support as VSCode. Follow [https://haskell-language-server.readthedocs.io/en/latest/configuration.html#coc haskell-language-server instruction] to add support for completion, linting, formatting, go to definition, etc.
endfunction
 
   
  +
* [https://github.com/luc-tielen/telescope_hoogle telescope_hoogle] Hoogle search from within Neovim.
nmap <silent> --s "=HaskellModuleSection()<CR>gp
 
</pre>
 
Like so:
 
<haskell>
 
   
  +
* [https://github.com/MrcJkb/neotest-haskell neotest-haskell] A [https://tree-sitter.github.io/tree-sitter/ tree-sitter] powered framework for interacting with Haskell tests in Neovim.
--------------------------------------------------------------------------------
 
-- my section
 
   
  +
* [https://github.com/nvim-treesitter/nvim-treesitter nvim-treesitter] Recommended for syntax highlighting.
</haskell>
 
   
  +
* [https://github.com/nvim-treesitter/nvim-treesitter-textobjects nvim-treesitter-textobjects] Uses tree-sitter to add syntax-aware textobjects (supports various languages, including Haskell).
   
  +
* [https://github.com/vim-test/vim-test vim-test] A Vim wrapper for running tests (including Haskell) on different granularities.
== 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":
 
<pre>
 
let s:width = 80
 
   
  +
* [https://github.com/aloussase/scout scout] Hackage search tool with a Neovim plugin.
   
  +
* [https://github.com/neovimhaskell/haskell-vim haskell-vim] Quote from [https://blog.jez.io/haskell-development-with-neovim/]: "It’s the filetype plugin for Haskell that should ship with Vim."
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"
 
   
  +
* [https://github.com/chrisdone/hindent Hindent] Haskell pretty printer
endfunction
 
   
  +
* [https://github.com/jaspervdj/stylish-haskell stylish-haskell] Haskell code prettifier
   
  +
* [https://github.com/w0rp/ale Ale] (Asynchronous Linting Engine)
nmap <silent> --h "=HaskellModuleHeader()<CR>:0put =<CR>
 
  +
<blockquote>
</pre>
 
  +
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.
like so:
 
  +
</blockquote>
<haskell>
 
  +
Comes with linters cabal_ghc, ghc, ghc_mod, hdevtools, hie, hlint, stack_build, stack_ghc
--------------------------------------------------------------------------------
 
-- |
 
-- Module : MyModule
 
-- Note : This is a preview
 
--
 
-- This is an empty module, to show the headercomment produced.
 
--
 
--------------------------------------------------------------------------------
 
   
  +
* [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.
</haskell>
 
  +
</blockquote>

Latest revision as of 22:01, 20 November 2022


There is a wide range of tools and corresponding VIM plugins that provide IDE-like features for Haskell development: haskell-language-server (implements the Language Server Protocol, thus needs a VIM LSP client), Intero, Dante, Codex, hdevtools and more. A less feature-rich but stable solution is to have ghcid running next to the editor window as described in [1]

Haskell Language Server

If you want to use the Haskell Language Server with Vim or Neovim, there are sections in the docs for that:

Assorted plugins for Vim or NeoVim

  • haskell-tools.nvim Neovim plugin that sets up Neovim's native LSP implementation to use haskell-language-server and provides various other Neovim tools for Haskell development. Aims to bring the Haskell experience in Neovim on par and beyond that of Visual Studio Code.
  • vim-test A Vim wrapper for running tests (including Haskell) on different granularities.
  • scout Hackage search tool with a Neovim plugin.
  • haskell-vim Quote from [2]: "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.