vim-hsimport


Ⅰ. 插件描述

Vim plugin for hsimport

Ⅱ. 基本信息

创建日期:  2013-12-26
使用用户:  4
Github星:  47
插件作者:  Daniel Trstenjak

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'dan-t/vim-hsimport'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'dan-t/vim-hsimport'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'dan-t/vim-hsimport'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/dan-t/vim-hsimport

Ⅳ. 文档说明

hsimport Vim Plugin

vim-hsimport is a Vim plugin that automatically creates import statements for
Haskell source files for the symbol/identifier under the cursor.

It can create import statements for the whole module, for only the desired
symbol/indentifier and is also able to create qualified module import
statements.

It uses hdevtools for its finding
of modules with the desired symbol. By using hdevtools it should also
support any cabal setting, a cabal sandbox and even stack.

Currently the biggest issue is if and how modules of your current project are
considered for the import, please see the issues section.

Features / Vim Commands

HsimportModule imports the whole module of the symbol/identifier under the cursor.

HsimportSymbol imports only the symbol/indentifier under the cursor.

If the symbol/indentifier under the cursor is contained in multiple modules,
then a selection dialog will be shown.

If the symbol has a module qualifier e.g. Text.pack, then both commands will create
a qualified import for the selected module. If the module Data.Text was selected,
then the created import statement will be import qualified Data.Text as Text.

The first call of either command might take several seconds, because hdevtools has to
cache all of the modul informations.

Installation

  1. Install hsimport, using a cabal sandbox is the recommend way:

     $ mkdir hsimport
     $ cd hsimport
     $ cabal sandbox init
     $ cabal install hsimport
    

    Your hsimport binary is now at hsimport/.cabal-sandbox/bin/hsimport.
    Ensure that the binary is reachable through your $PATH environment variable.

  2. Install hdevtools, using a cabal sandbox is the recommend way:

     $ mkdir hdevtools
     $ cd hdevtools
     $ cabal sandbox init
     $ cabal install hdevtools
    

    Your hdevtools binary is now at hdevtools/.cabal-sandbox/bin/hdevtools.
    Ensure that the binary is reachable through your $PATH environment variable.

  3. Install vim-hsimport. pathogen.vim
    is the recommended way:
    $ cd ~/.vim/bundle
    $ git clone https://github.com/dan-t/vim-hsimport

Configuration

You most likely want to add keybindings for the two available commands into your ~/.vimrc e.g.:

autocmd FileType haskell nmap <silent> <F1> :silent update <bar> HsimportModule<CR>
autocmd FileType haskell nmap <silent> <F2> :silent update <bar> HsimportSymbol<CR>

How the imports are pretty printed and where they're placed can be configured. Please take a look
at the README of hsimport.

Issues

Currently the modules for your own project are considered by a quite simple heuristic.
The source tree is searched by grep with a regex that should "mostly" match
the symbol with data/type definitions and with top level function/operator
definitions.

I'm very open for changing this to something more robust. The solution can return false
positives, because the real inspection is done by hdevtools, it's just about to reduce
the number of source files given to hdevtools and that it's still fast enough to be
interactive usable.

Credits

Heavily inspired by vim-hdevtools.

添加新评论