Skip to content
This repository has been archived by the owner on Aug 5, 2023. It is now read-only.

adaszko/intero.vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 

Repository files navigation

A simple Intero integration for Vim.

Usage

  1. cd ~/.vim/pack/bundle/start/

  2. git clone https://github.com/adaszko/intero.vim.git

  3. Add to your .vimrc:

augroup my_haskell
    autocmd!

    autocmd FileType haskell nmap <silent> <buffer> <LocalLeader>I :call intero#toggle()<CR>

    " For use in Spec.hs;  Doesn't do :load automatically
    autocmd FileType haskell nmap <silent> <buffer> <LocalLeader>T :call intero#toggle_test()<CR>

    " intero#go_to_definition() accepts normal mode commands to execute after a successful jump
    autocmd FileType haskell noremap <silent> <buffer> gd :call intero#go_to_definition('zz')<CR>
    autocmd FileType haskell setlocal omnifunc=intero#omnicomplete

    autocmd FileType haskell xnoremap <silent> <buffer> <LocalLeader>t :call intero#type_of_selection()<CR>
    autocmd FileType haskell nnoremap <silent> <buffer> <LocalLeader>t :call intero#type_at_cursor()<CR>
    autocmd FileType haskell nnoremap <silent> <buffer> <LocalLeader>i :call intero#send_line(printf(":info %s", expand("<cword>")))<CR>
    autocmd FileType haskell nnoremap <silent> <buffer> <LocalLeader>k :call intero#send_line(printf(":kind %s", expand("<cword>")))<CR>
    autocmd FileType haskell nnoremap <silent> <buffer> <LocalLeader>r :call intero#send_line(":reload")<CR>
    autocmd FileType haskell xnoremap <silent> <buffer> <LocalLeader>s :call intero#send_selection()<CR>
    autocmd FileType haskell nnoremap <silent> <buffer> <LocalLeader>s :call intero#send_current_line()<CR>

    " Populates the location list
    autocmd FileType haskell nnoremap <silent> <buffer> <LocalLeader>R :call intero#uses_at_cursor()<CR>

    autocmd FileType haskell nnoremap <silent> <buffer> <LocalLeader>l :call intero#send_line(printf(":load %s", expand("%")))<CR>

    function! s:reload_if_intero_running()
        if intero#is_open()
            call intero#send_keys(':reload
')
        endif
    endfunction

    " Does :reload on every write of a Haskell buffer, along with clearing the screen.
    autocmd BufWritePost *.hs :call s:reload_if_intero_running()

    autocmd FileType intero nnoremap <silent> <buffer> <CR> :call intero#jump_to_error_at_cursor()<CR>
augroup END
  1. Build Intero within your stack project: stack build intero
  2. Open your project file and use \I to start the Intero shell (adjust for your <LocalLeader> setting)

Tips

Completion and go-to-def smarts work on the last successfully loaded version of a Haskell module. If you're in the middle of resolving type errors and still want to use up-to-date version of your code, you may want to use :set -fdefer-type-errors option, or even define a mapping for it:

[...]
autocmd FileType haskell nnoremap <silent> <buffer> <LocalLeader>d :call intero#send_line(":set -fdefer-type-errors")<CR>
[...]

(Not exhaustive) demo

  • :reload, :kind, :type, go-to-definition

  • :type-at (get type of an expression)

  • 'omnifunc' (Vim's <C-X><C-O> completion)

Changelog

Breaking changes:

  • 2019-05-26 Added fallback to open web browser in intero#go_to_definition()
    • Won't work with anything else than macOS and Google Chrome (porting is trivial)
  • 2019-05-26 Removed intero#go_to_def_or_open_browser()
  • 2019-04-13 :uses now populates location list instead of quickfix list
  • 2019-04-13 Removed intero#stack_build_toggle(). stack build --file-watch is as usable outside of Vim.

Backward-compatible changes:

  • 2019-05-26 Populate quickfix with GHCi errors on :reload
  • 2019-04-26 Added intero#go_to_def_or_open_browser()
  • 2019-04-22 Quick jumping into error location
  • 2019-04-22 Support e.g. centering after a successful go-to-def
  • 2019-04-22 Support :reloading on a buffer write

About

Intero integration for Vim

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published