Windows下配置Storm源码阅读环境(vim+ctags)

2014年7月29日

此处为Win7 64位系统。

1. 安装vim
下载并安装vim的Windows版本:ftp://ftp.vim.org/pub/vim/pc/gvim74.exe
安装到任意位置,以下称为$VIM, 将$VIM\vim74加入到PATH变量。

2. 安装VimClojure & TagList
VimClojure网址为http://www.vim.org/scripts/script.php?script_id=2501,下载 vimclojure-2.3.6.zip
解压到$VIM\vimfiles中

TagList网址为http://www.vim.org/scripts/script.php?script_id=273,下载 taglist_46.zip
解压到$VIM\vimfiles中

3. 安装及配置ctags
直接去ctags官网下载windows版本,下载链接为http://prdownloads.sourceforge.net/ctags/ctags58.zip
该压缩包里包含了源码和exe,只要那个ctags.exe就行了,将其解压到$VIM\vim72下,以在命令行可以直接调用。

ctags默认不识别clojure文件,可以在$HOME\ctags.cnf中补充。$HOME指的是cmd启动时的初始目录。
手动创建$HOME\ctags.cnf,加入内容:
--langmap=Lisp:+.clj
即用Lisp语法解析clojure代码。此后用ctags --list-maps指令可以看到clj文件已归入Lisp类:


在cmd下走到storm源码所在目录,比如主要想看storm-core的源码,走到其src目录下,执行 ctags -R。之后会在本目录生成一个tags文件。

4. 配置vimrc
编辑$VIM/_vimrc,加入如下内容:

set nu
colorscheme desert
set history=50      " keep 50 lines of command line history
set ruler           " show the cursor position all the time
set showcmd         " display incomplete commands
set incsearch       " do incremental searching

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " For all python source files set 'tab' to 4 spaces
  autocmd FileType python setlocal et sta sw=4 sts=4

  " For all java
  autocmd FileType java setlocal omnifunc=javacomplete#Complete
  autocmd FileType java setlocal completefunc=javacomplete#CompleteParamsInfo

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

else

  set autoindent          " always set autoindenting on

endif " has("autocmd")

""""""""""""""""""""""""""""""
" Tag list (ctags)
""""""""""""""""""""""""""""""
let Tlist_Ctags_Cmd = 'ctags'
let Tlist_Show_One_File = 1         "不同时显示多个文件的tag,只显示当前文件的
let Tlist_Exit_OnlyWindow = 1       "如果taglist窗口是最后一个窗口,则退出vim
let Tlist_Use_Right_Window = 1      "在右侧窗口中显示taglist窗口
map <silent> <F9> :TlistToggle<cr>
let tlist_clojure_settings = 'lisp;f:function'



5. 功能展示
进入storm-trunk\storm-core\src目录,执行ctags -R clj jvm,生成tags文件。
再执行gvim clj\backtype\storm\daemon\nimbus.clj打开一个文件。
按F9可在右侧看到函数列表:


将光标移到变量名下,按Ctrl+]可以跳转到定义处,按Ctrl+T可以跳回来。也可以在vim命令中直接输入tag,如输入
:tag mk-worker
可跳转到worker.clj的mk-worker函数中。

猜你喜欢

转载自blog.csdn.net/huang_quanlong/article/details/38308213