将Vim打造为ScalaIDE

文中的所有描述都基于 Windows

对于Windows需要先安装 GitCurl, 然后我将配置 Vundle 来管理依赖,这样依赖的安装和删除都会很方便

安装步骤

  1. 安装Git

    下载 git for windows

    安装git。记得安装的时候选中 Run Git from the Windows Command Prompt

    确认安装

    c:\>git --version
    
  2. 安装curl

    Vundle 需要curl的支持

    下载 curl

    到 $GIT_HOME/cmd 添加一个脚本 curl.cmd

    @rem Do not use "echo off" to not affect any child calls.
    @setlocal
    
    @rem Get the abolute path to the parent directory, which is assumed to be the
    @rem Git installation root.
    @for /F "delims=" %%I in ("%~dp0..") do @set git_install_root=%%~fI
    @set PATH=%git_install_root%\bin;%git_install_root%\mingw\bin;%PATH%
    
    @if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%
    @if not exist "%HOME%" @set HOME=%USERPROFILE%
    
    @curl.exe %*
    

    确认安装

    C:\> curl --version
    
  3. 安装 Vundle

    cd <vim目录>
    git clone https://github.com/gmarik/vundle.git vimfiles/bundle/vundle
    

    对于windows来说,还需要在 _vimrc 中添加

    set rtp+=$VIM/vimfiles/bundle/vundle
    call vundle#rc()
    

    这样vundle才能正常启动

  1. 编辑 _vimrc (位于Vim目录) 配置需要的插件。 可以参考文章后面的依赖列表。
  1. 打开 gvim,然后执行

    :BundleInstall
    
  1. 配置ctags 使其能够对 scala 列出tag

    --langdef=scala
    --langmap=scala:.scala
    --regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*class[ \t]+([a-zA-Z0-_]+)/\4/c,classes/
    --regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*object[ \t]+([a-zA-Z0-_]+)/\4/c,objects/
    --regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*case class[ \t]+([a-zA-Z0-_]+)/\4/c,case classes/
    --regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*case object[ \t]+([a-zA-Z0-_]+)/\4/c,case objects/
    --regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*trait[ \t]+([a-zA-Z0-_]+)/\4/t,traits/
    --regex-scala=/^[ \t]*type[ \t]+([a-zA-Z0-_]+)/\1/T,types/
    --regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*def[ \t]+([a-zA-Z0-_]+)/\3/m,methods/
    --regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*val[ \t]+([a-zA-Z0-_]+)/\3/l,constants/
    --regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*var[ \t]+([a-zA-Z0-_]+)/\3/l,variables/
    --regex-scala=/^[ \t]*package[ \t]+([a-zA-Z0-_.]+)/\1/p,packages/
    
到工程目录下

    ctags -R . --exclude=target --exclude=vendor

最后列一些我配置的依赖

" ===========  Basic Bundle
Bundle 'gmarik/vundle'

" ===========  Theame
Bundle 'molokai'
Bundle 'rickharris/vim-blackboard'
Bundle 'altercation/vim-colors-solarized'
Bundle 'tomasr/molokai'
Bundle 'rickharris/vim-monokai'
Bundle 'tpope/vim-vividchalk'
Bundle 'Lokaltog/vim-distinguished'

Bundle 'Markdown'
Bundle 'Markdown-syntax'

"     ---------  Scala Support
Bundle 'derekwyatt/vim-scala'
"     ---------  Language Package Support
Bundle 'sheerun/vim-polyglot'


" ===========  IDE Features

Bundle 'majutsushi/tagbar'

"   ---------   Project Navigation
Bundle 'scrooloose/nerdtree'

"   ---------   Auto Complete
Bundle 'Shougo/neocomplcache.vim'
Bundle 'Lokaltog/vim-powerline'
Bundle 'vim-scripts/taglist.vim'
Bundle 'fholgado/minibufexpl.vim'
Bundle 'Raimondi/delimitMate'

参考资料

[1]Vundle for windows