Difference between revisions of "Vim"
Wlangstroth (talk | contribs) m (filling out the intended sentence) |
|||
(15 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
[[Category:Development tools]] |
[[Category:Development tools]] |
||
− | This page is intended for Haskell vim-users. |
||
+ | = Vim as a Haskell IDE = |
||
− | = Indentation = |
||
+ | There is a wide range of tools and corresponding VIM plugins that provide IDE-like features for Haskell development: haskell-ide-engine (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] |
||
− | The following setup from merijn @ #haskell ensures you use spaces not tabs for indentation for generally sane behaviour: |
||
− | |||
− | <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 shiftround "Round indent to nearest shiftwidth multiple |
||
− | </pre> |
||
= Plugins = |
= 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 |
||
+ | * [https://github.com/neoclide/coc.nvim coc.nvim] Intellisense engine for Vim8 & Neovim, full language server protocol support as VSCode. Follow haskell-ide-engine [https://github.com/haskell/haskell-ide-engine#coc instructions] to add support for completion, linting, formatting, go to definition, etc. |
||
− | function! HaskellModuleSection(...) |
||
− | let name = 0 < a:0 ? a:1 : inputdialog("Section name: ") |
||
+ | * [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." |
||
− | return repeat('-', s:width) . "\n" |
||
− | \ . "-- " . name . "\n" |
||
− | \ . "\n" |
||
+ | * [https://github.com/chrisdone/hindent Hindent] Haskell pretty printer |
||
− | endfunction |
||
+ | * [https://github.com/jaspervdj/stylish-haskell stylish-haskell] Haskell code prettifier |
||
− | nmap <silent> --s "=HaskellModuleSection()<CR>gp |
||
− | </pre> |
||
− | Like so: |
||
− | <haskell> |
||
+ | * [https://github.com/w0rp/ale Ale] (Asynchronous Linting Engine) |
||
− | -------------------------------------------------------------------------------- |
||
+ | <blockquote> |
||
− | -- my section |
||
+ | 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. |
||
− | |||
− | </ |
+ | </blockquote> |
+ | Comes with linters cabal_ghc, ghc, ghc_mod, hdevtools, hie, hlint, stack_build, stack_ghc |
||
− | |||
− | |||
− | == 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 |
||
− | |||
− | |||
− | 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> |
||
− | </pre> |
||
− | like so: |
||
− | <haskell> |
||
− | -------------------------------------------------------------------------------- |
||
− | -- | |
||
− | -- Module : MyModule |
||
− | -- Note : This is a preview |
||
− | -- |
||
− | -- This is an empty module, to show the headercomment produced. |
||
− | -- |
||
− | -------------------------------------------------------------------------------- |
||
− | |||
− | |||
− | </haskell> |
||
− | |||
− | = List of Plugins |
||
* [https://github.com/bitc/vim-hdevtools Hdevtools] taken from the github page: |
* [https://github.com/bitc/vim-hdevtools Hdevtools] taken from the github page: |
||
Line 91: | Line 27: | ||
This is the Vim plugin that integrates Vim with hdevtools. |
This is the Vim plugin that integrates Vim with hdevtools. |
||
</blockquote> |
</blockquote> |
||
− | |||
− | |||
− | *[https://github.com/lukerandall/haskellmode-vim Haskellmode-vim] from the github: |
||
− | <blockquote> |
||
− | The Haskell mode plugins provide advanced support for Haskell development |
||
− | using GHC/GHCi on Windows and Unix-like systems. The functionality is |
||
− | based on Haddock-generated library indices, on GHCi's interactive |
||
− | commands, or on simply activating (some of) Vim's built-in program editing |
||
− | support in Haskell-relevant fashion. These plugins live side-by-side with |
||
− | the pre-defined |syntax-highlighting| support for |haskell| sources, and |
||
− | any other Haskell-related plugins you might want to install (see |
||
− | |haskellmode-resources|). |
||
− | |||
− | The Haskell mode plugins consist of three filetype plugins (haskell.vim, |
||
− | haskell_doc.vim, haskell_hpaste.vim), which by Vim's |filetype| detection |
||
− | mechanism will be auto-loaded whenever files with the extension '.hs' are |
||
− | opened, and one compiler plugin (ghc.vim) which you will need to load from |
||
− | your vimrc file (see |haskellmode-settings|). |
||
− | </blockquote> |
||
− | |||
− | * [https://github.com/eagletmt/ghcmod-vim Ghcmod-vim] from the github Page: |
||
− | <blockquote> |
||
− | Displaying the type of sub-expressions (ghc-mod type) |
||
− | Displaying error/warning messages and their locations (ghc-mod check and ghc-mod lint) |
||
− | Displaying the expansion of splices (ghc-mod expand) |
||
− | Completions are supported by another plugin. See neco-ghc . |
||
− | </blockquote>. |
||
− | |||
− | * [https://github.com/scrooloose/syntastic Syntastic] supports Haskell and several other languages. From the github |
||
− | <blockquote> |
||
− | Syntastic is a syntax checking plugin that runs files through external syntax checkers and displays any resulting errors to the user. This can be done on demand, or automatically as files are saved. If syntax errors are detected, the user is notified and is happy because they didn't have to compile their code or execute their script to find them. |
||
− | |||
− | At the time of this writing, syntax checking plugins exist for applescript, c, coffee, cpp, css, cucumber, cuda, docbk, erlang, eruby, fortran, gentoo_metadata, go, haml, haskell, html, javascript, json, less, lua, matlab, perl, php, puppet, python, rst, ruby, sass/scss, sh, tcl, tex, vala, xhtml, xml, xslt, yaml, zpt |
||
− | </blockquote> |
||
− | |||
− | * [https://github.com/ujihisa/neco-ghc Neco-ghc] power by ghcmod-vim for completion of pragma, modules, functions and more. |
||
− | |||
− | * [http://blog-mno2.csie.org/blog/2011/11/17/vim-plugins-for-haskell-programmers/ Addition list] with some missing here with screen shots of many of the above. |
Revision as of 17:19, 7 March 2020
Vim as a Haskell IDE
There is a wide range of tools and corresponding VIM plugins that provide IDE-like features for Haskell development: haskell-ide-engine (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]
Plugins
- coc.nvim Intellisense engine for Vim8 & Neovim, full language server protocol support as VSCode. Follow haskell-ide-engine instructions to add support for completion, linting, formatting, go to definition, etc.
- haskell-vim Quote from [2]: "It’s the filetype plugin for Haskell that should ship with Vim."
- Hindent Haskell pretty printer
- stylish-haskell Haskell code prettifier
- 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 taken from the github page:
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.