New

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  21 Posts :: 0 Stories :: 4 Comments :: 0 Trackbacks
_vimrc  

如果文件格式为java则使用indent/java.vim的缩进规则

autocmd FileType java source Vim/vim73/indent/java.vim
新建一个java文件抽入指定文件

autocmd BufNewFile *.java 0r e:/java/my.txt

设置Tlist

let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1  Tlist是最后一个窗口关闭时退出

设置winmanager

let g:winManagerWindowLayout = "BufExplorer,FileExplorer|TagList"
let g:winManagerWidth = 30

设置键盘映射


nmap wm :WMToggle<cr>


posted on 2011-10-31 22:22 H.C 阅读(4140) 评论(2)  编辑  收藏

Feedback

# re: VIM for java IDE 2011-11-09 21:52 H.C
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Maintainer: amix the lucky stiff
" http://amix.dk - amix@amix.dk
"
" Version: 3.6 - 25/08/10 14:40:30
"
" Blog_post:
" http://amix.dk/blog/post/19486#The-ultimate-vim-configuration-vimrc
" Syntax_highlighted:
" http://amix.dk/vim/vimrc.html
" Raw_version:
" http://amix.dk/vim/vimrc.txt
"
" How_to_Install_on_Unix:
" $ mkdir ~/.vim_runtime
" $ svn co svn://orangoo.com/vim ~/.vim_runtime
" $ cat ~/.vim_runtime/install.sh
" $ sh ~/.vim_runtime/install.sh <system>
" <sytem> can be `mac`, `linux` or `windows`
"
" How_to_Upgrade:
" $ svn update ~/.vim_runtime
"
" Sections:
" -> General
" -> VIM user interface
" -> Colors and Fonts
" -> Files and backups
" -> Text, tab and indent related
" -> Visual mode related
" -> Command mode related
" -> Moving around, tabs and buffers
" -> Statusline
" -> Parenthesis/bracket expanding
" -> General Abbrevs
" -> Editing mappings
"
" -> Cope
" -> Minibuffer plugin
" -> Omni complete functions
" -> Python section
" -> JavaScript section
"
"
" Plugins_Included:
" > minibufexpl.vim - http://www.vim.org/scripts/script.php?script_id=159
" Makes it easy to get an overview of buffers:
" info -> :e ~/.vim_runtime/plugin/minibufexpl.vim
"
" > bufexplorer - http://www.vim.org/scripts/script.php?script_id=42
" Makes it easy to switch between buffers:
" info -> :help bufExplorer
"
" > yankring.vim - http://www.vim.org/scripts/script.php?script_id=1234
" Emacs's killring, useful when using the clipboard:
" info -> :help yankring
"
" > surround.vim - http://www.vim.org/scripts/script.php?script_id=1697
" Makes it easy to work with surrounding text:
" info -> :help surround
"
" > snipMate.vim - http://www.vim.org/scripts/script.php?script_id=2540
" Snippets for many languages (similar to TextMate's):
" info -> :help snipMate
"
" > mru.vim - http://www.vim.org/scripts/script.php?script_id=521
" Plugin to manage Most Recently Used (MRU) files:
" info -> :e ~/.vim_runtime/plugin/mru.vim
"
" > Command-T - http://www.vim.org/scripts/script.php?script_id=3025
" Command-T plug-in provides an extremely fast, intuitive mechanism for opening filesa:
" info -> :help CommandT
" screencast and web-help -> http://amix.dk/blog/post/19501
"
"
" Revisions:
" > 3.6: Added lots of stuff (colors, Command-T, Vim 7.3 persistent undo etc.)
" > 3.5: Paste mode is now shown in status line if you are in paste mode
" > 3.4: Added mru.vim
" > 3.3: Added syntax highlighting for Mako mako.vim
" > 3.2: Turned on python_highlight_all for better syntax
" highlighting for Python
" > 3.1: Added revisions ;) and bufexplorer.vim
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
set history=700

" Enable filetype plugin
filetype plugin on
filetype indent on

" Set to auto read when a file is changed from the outside
set autoread

" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","

" Fast saving
nmap <leader>w :w!<cr>

" Fast editing of the .vimrc
map <leader>e :e! ~/.vim_runtime/vimrc<cr>

" When vimrc is edited, reload it
autocmd! bufwritepost vimrc source ~/.vim_runtime/vimrc


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 7 lines to the curors - when moving vertical..
set so=7

set wildmenu "Turn on WiLd menu

set ruler "Always show current position

set cmdheight=2 "The commandbar height

set hid "Change buffer - without saving

" Set backspace config
set backspace=eol,start,indent
set whichwrap+=<,>,h,l

set ignorecase "Ignore case when searching
set smartcase

set hlsearch "Highlight search things

set incsearch "Make search act like search in modern browsers
set nolazyredraw "Don't redraw while executing macros

set magic "Set magic on, for regular expressions

set showmatch "Show matching bracets when text indicator is over them
set mat=2 "How many tenths of a second to blink

" No sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax enable "Enable syntax hl

" Set font according to system
if MySys() == "mac"
set gfn=Menlo:h14
set shell=/bin/bash
elseif MySys() == "windows"
set gfn=Bitstream\ Vera\ Sans\ Mono:h10
elseif MySys() == "linux"
set gfn=Monospace\ 10
set shell=/bin/bash
endif

if has("gui_running")
set guioptions-=T
set t_Co=256
set background=dark
colorscheme peaksea
set nonu
else
colorscheme zellner
set background=dark

set nonu
endif

set encoding=utf8
try
lang en_US
catch
endtry

set ffs=unix,dos,mac "Default file types


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups and undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn backup off, since most stuff is in SVN, git anyway...
set nobackup
set nowb
set noswapfile

"Persistent undo
try
if MySys() == "windows"
set undodir=C:\Windows\Temp
else
set undodir=~/.vim_runtime/undodir
endif

set undofile
catch
endtry


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set expandtab
set shiftwidth=4
set tabstop=4
set smarttab

set lbr
set tw=500

set ai "Auto indent
set si "Smart indet
set wrap "Wrap lines


""""""""""""""""""""""""""""""
" => Visual mode related
""""""""""""""""""""""""""""""
" Really useful!
" In visual mode when you press * or # to search for the current selection
vnoremap <silent> * :call VisualSearch('f')<CR>
vnoremap <silent> # :call VisualSearch('b')<CR>

" When you press gv you vimgrep after the selected text
vnoremap <silent> gv :call VisualSearch('gv')<CR>
map <leader>g :vimgrep // **/*.<left><left><left><left><left><left><left>


function! CmdLine(str)
exe "menu Foo.Bar :" . a:str
emenu Foo.Bar
unmenu Foo
endfunction

" From an idea by Michael Naumann
function! VisualSearch(direction) range
let l:saved_reg = @"
execute "normal! vgvy"

let l:pattern = escape(@", '\\/.*$^~[]')
let l:pattern = substitute(l:pattern, "\n$", "", "")

if a:direction == 'b'
execute "normal ?" . l:pattern . "^M"
elseif a:direction == 'gv'
call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
elseif a:direction == 'f'
execute "normal /" . l:pattern . "^M"
endif

let @/ = l:pattern
let @" = l:saved_reg
endfunction



"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Command mode related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Smart mappings on the command line
cno $h e ~/
cno $d e ~/Desktop/
cno $j e ./
cno $c e <C-\>eCurrentFileDir("e")<cr>

" $q is super useful when browsing on the command line
cno $q <C-\>eDeleteTillSlash()<cr>

" Bash like keys for the command line
cnoremap <C-A> <Home>
cnoremap <C-E> <End>
cnoremap <C-K> <C-U>

cnoremap <C-P> <Up>
cnoremap <C-N> <Down>

" Useful on some European keyboards
map ½ $
imap ½ $
vmap ½ $
cmap ½ $


func! Cwd()
let cwd = getcwd()
return "e " . cwd
endfunc

func! DeleteTillSlash()
let g:cmd = getcmdline()
if MySys() == "linux" || MySys() == "mac"
let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*", "\\1", "")
else
let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\]\\).*", "\\1", "")
endif
if g:cmd == g:cmd_edited
if MySys() == "linux" || MySys() == "mac"
let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*/", "\\1", "")
else
let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\\]\\).*\[\\\\\]", "\\1", "")
endif
endif
return g:cmd_edited
endfunc

func! CurrentFileDir(cmd)
return a:cmd . " " . expand("%:p:h") . "/"
endfunc


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around, tabs and buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Map space to / (search) and c-space to ? (backgwards search)
map <space> /
map <c-space> ?
map <silent> <leader><cr> :noh<cr>

" Smart way to move btw. windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l

" Close the current buffer
map <leader>bd :Bclose<cr>

" Close all the buffers
map <leader>ba :1,300 bd!<cr>

" Use the arrows to something usefull
map <right> :bn<cr>
map <left> :bp<cr>

" Tab configuration
map <leader>tn :tabnew<cr>
map <leader>te :tabedit
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove

" When pressing <leader>cd switch to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>


command! Bclose call <SID>BufcloseCloseIt()
function! <SID>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")

if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif

if bufnr("%") == l:currentBufNum
new
endif

if buflisted(l:currentBufNum)
execute("bdelete! ".l:currentBufNum)
endif
endfunction

" Specify the behavior when switching between buffers
try
set switchbuf=usetab
set stal=2
catch
endtry


""""""""""""""""""""""""""""""
" => Statusline
""""""""""""""""""""""""""""""
" Always hide the statusline
set laststatus=2

" Format the statusline
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c


function! CurDir()
let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g")
return curdir
endfunction

function! HasPaste()
if &paste
return 'PASTE MODE '
else
return ''
endif
endfunction


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Parenthesis/bracket expanding
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
vnoremap $1 <esc>`>a)<esc>`<i(<esc>
vnoremap $2 <esc>`>a]<esc>`<i[<esc>
vnoremap $3 <esc>`>a}<esc>`<i{<esc>
vnoremap $$ <esc>`>a"<esc>`<i"<esc>
vnoremap $q <esc>`>a'<esc>`<i'<esc>
vnoremap $e <esc>`>a"<esc>`<i"<esc>

" Map auto complete of (, ", ', [
inoremap $1 ()<esc>i
inoremap $2 []<esc>i
inoremap $3 {}<esc>i
inoremap $4 {<esc>o}<esc>O
inoremap $q ''<esc>i
inoremap $e ""<esc>i
inoremap $t <><esc>i


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General Abbrevs
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
iab xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Editing mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Remap VIM 0
map 0 ^

"Move a line of text using ALT+[jk] or Comamnd+[jk] on mac
nmap <M-j> mz:m+<cr>`z
nmap <M-k> mz:m-2<cr>`z
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z

if MySys() == "mac"
nmap <D-j> <M-j>
nmap <D-k> <M-k>
vmap <D-j> <M-j>
vmap <D-k> <M-k>
endif

"Delete trailing white space, useful for Python ;)
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
autocmd BufWrite *.py :call DeleteTrailingWS()

set guitablabel=%t


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Cope
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Do :help cope if you are unsure what cope is. It's super useful!
map <leader>cc :botright cope<cr>
map <leader>n :cn<cr>
map <leader>p :cp<cr>


""""""""""""""""""""""""""""""
" => bufExplorer plugin
""""""""""""""""""""""""""""""
let g:bufExplorerDefaultHelp=0
let g:bufExplorerShowRelativePath=1
map <leader>o :BufExplorer<cr>


""""""""""""""""""""""""""""""
" => Minibuffer plugin
""""""""""""""""""""""""""""""
let g:miniBufExplModSelTarget = 1
let g:miniBufExplorerMoreThanOne = 2
let g:miniBufExplModSelTarget = 0
let g:miniBufExplUseSingleClick = 1
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplVSplit = 25
let g:miniBufExplSplitBelow=1

let g:bufExplorerSortBy = "name"

autocmd BufRead,BufNew :call UMiniBufExplorer

map <leader>u :TMiniBufExplorer<cr>


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Omni complete functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd FileType css set omnifunc=csscomplete#CompleteCSS


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Spell checking
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Pressing ,ss will toggle and untoggle spell checking
map <leader>ss :setlocal spell!<cr>

"Shortcuts using <leader>
map <leader>sn ]s
map <leader>sp [s
map <leader>sa zg
map <leader>s? z=


""""""""""""""""""""""""""""""
" => Python section
""""""""""""""""""""""""""""""
let python_highlight_all = 1
au FileType python syn keyword pythonDecorator True None False self

au BufNewFile,BufRead *.jinja set syntax=htmljinja
au BufNewFile,BufRead *.mako set ft=mako

au FileType python inoremap <buffer> $r return
au FileType python inoremap <buffer> $i import
au FileType python inoremap <buffer> $p print
au FileType python inoremap <buffer> $f #--- PH ----------------------------------------------<esc>FP2xi
au FileType python map <buffer> <leader>1 /class
au FileType python map <buffer> <leader>2 /def
au FileType python map <buffer> <leader>C ?class
au FileType python map <buffer> <leader>D ?def


""""""""""""""""""""""""""""""
" => JavaScript section
"""""""""""""""""""""""""""""""
au FileType javascript call JavaScriptFold()
au FileType javascript setl fen
au FileType javascript setl nocindent

au FileType javascript imap <c-t> AJS.log();<esc>hi
au FileType javascript imap <c-a> alert();<esc>hi

au FileType javascript inoremap <buffer> $r return
au FileType javascript inoremap <buffer> $f //--- PH ----------------------------------------------<esc>FP2xi

function! JavaScriptFold()
setl foldmethod=syntax
setl foldlevelstart=1
syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend

function! FoldText()
return substitute(getline(v:foldstart), '{.*', '{...}', '')
endfunction
setl foldtext=FoldText()
endfunction


""""""""""""""""""""""""""""""
" => MRU plugin
""""""""""""""""""""""""""""""
let MRU_Max_Entries = 400
map <leader>f :MRU<CR>


""""""""""""""""""""""""""""""
" => Command-T
""""""""""""""""""""""""""""""
let g:CommandTMaxHeight = 15
set wildignore+=*.o,*.obj,.git,*.pyc
noremap <leader>j :CommandT<cr>
noremap <leader>y :CommandTFlush<cr>


""""""""""""""""""""""""""""""
" => Vim grep
""""""""""""""""""""""""""""""
let Grep_Skip_Dirs = 'RCS CVS SCCS .svn generated'
set grepprg=/bin/grep\ -nH



"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => MISC
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm

"Quickly open a buffer for scripbble
map <leader>q :e ~/buffer<cr>
au BufRead,BufNewFile ~/buffer iab <buffer> xh1 ===========================================

map <leader>pp :setlocal paste!<cr>

map <leader>bb :cd ..<cr>
  回复  更多评论
  

# re: VIM for java IDE 2011-11-11 16:25 H.C
需要用到的插件:

taglist需要ctags支持

ctags.exe:http://ctags.sourceforge.net/

taglist显示tag列表

taglist:http://www.vim.org/scripts/script.php?script_id=273

显示buf列表:

bufexplorer:http://www.vim.org/scripts/script.php?script_id=42

Nerd_Tree文件浏览

Nerd_tree:http://www.vim.org/scripts/script.php?script_id=1658

界面管理插件:

winmanager:http://www.vim.org/scripts/script.php?script_id=95



一、ctags:

下载解压后是源码,感觉就那个exe文件有点用。直接放到一个目录里,D:\ctags58。

设置一下环境变量。path=D:\ctags58。这样可以直接运行目录下面的ctags.exe文件。或者直接把ctags.exe放入windows的目录里。

vimrc中的设置:
view sourceprint?
1 "生成一个tags文件
2 nmap <F9> <Esc>:!ctags -R *<CR>



二、taglist设置:

下载解压到相应的vim文件夹中。

vimrc中设置:
view sourceprint?
01 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
02
03 "设置Taglist
04
05 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
06
07 " 这项必须设定,否则出错,配置taglist的ctags路径
08
09 let Tlist_Ctags_Cmd = 'D:\ctags58\ctags.exe'
10
11
12
13 " 不同时显示多个文件的 tag ,只显示当前文件的
14
15 let Tlist_Show_One_File=1
16
17
18
19 " 如果 taglist 窗口是最后一个窗口,则退出 vim
20
21 let Tlist_Exit_OnlyWindow=1
22
23
24
25 "让当前不被编辑的文件的方法列表自动折叠起来
26
27 let Tlist_File_Fold_Auto_Close=1
28
29
30
31 "把taglist窗口放在屏幕的右侧,缺省在左侧
32
33 let Tlist_Use_Right_Window=1
34
35
36
37 "显示taglist菜单
38
39 let Tlist_Show_Menu=1
40
41
42
43 "启动vim自动打开taglist
44
45 "let Tlist_Auto_Open=1

启动自动打开这个选项暂时不设置。后面要让winmanager调用taglist。



三、bufexplorer:

下载解压,没啥说的。



四、winmanager:

下载解压,vimrc中的设置:
view sourceprint?
01 """""""""""""""""""""""""""""""
02
03 "" winManager setting
04
05 """""""""""""""""""""""""""""""
06
07 "设置界面分割
08
09 "let g:winManagerWindowLayout = "BufExplorer,FileExplorer|TagList"
10
11 let g:winManagerWindowLayout = "TagList|FileExplorer,BufExplorer"
12
13
14
15 "设置winmanager的宽度,默认为25
16
17 let g:winManagerWidth = 30
18
19
20
21 "定义打开关闭winmanager按键
22
23 nmap <silent> <F8> :WMToggle<cr>



以上3个插件安装设置完毕后,基本的界面功能就可以实现了。按F8可以打开/关闭界面。同时显示taglist和fileexplorer。在fileexplorer窗口中按<c-n>可以切换到bufexplorer窗口。

上述设置好后,有3个问题:

1 我想让插件显示在右侧,但是winmanager里面没有此选项

2 进入vim时候不能自动打开winmanager,winmanager不像taglist支持该功能

3 退出时不会像只有taglist时候那样,退出当前文件就会退出vim了

经过多次修改代码终于实在了上述3个功能。



五、将插件显示在右侧

打开winmanager.vim,在function! <SID>StartWindowsManager()函数中修改:

将:wincmd H 修改为wincmd L:
view sourceprint?
1 " for now assume that the explorer windows always stay on the left.
2
3 " TODO: make this optional later
4
5 " make the explorers window always stay on the right ---by chenyong
6
7 " wincmd H
8
9 wincmd L



六、进入vim自动打开winmanager

这个功能作为可选功能,我们可以在vimrc中设置:
view sourceprint?
1 "在进入vim时自动打开winmanager
2
3 let g:AutoOpenWinManager = 1

就可以让winmanager自动打开。

在winmanager.vim中修改:

view sourceprint?
1 "set auto open Winmanager
2
3 if g:AutoOpenWinManager
4
5 autocmd VimEnter * nested call s:StartWindowsManager()|1wincmd w
6
7 endif



七、退出缓冲区时,自动退出vim

这个功能是参考了taglist的自动退出功能,在taglist.vim中修改的。

函数:function! s:Tlist_Window_Exit_Only_Window()中的winbunr(2)改为winbunr(3),即只剩2个窗口时关闭,考虑到2个窗口肯定是同时存在,所以这样还是可行的:
view sourceprint?
01 function! s:Tlist_Window_Exit_Only_Window()
02
03 " Before quitting Vim, delete the taglist buffer so that
04
05 " the '0 mark is correctly set to the previous buffer.
06
07 if v:version < 700
08
09 if winbufnr(3) == -1
10
11 bdelete
12
13 quit
14
15 endif
16
17 else
18
19 if winbufnr(3) == -1
20
21 if tabpagenr('$') == 1
22
23 " Only one tag page is present
24
25 bdelete
26
27 quit
28
29 else
30
31 " More than one tab page is present. Close only the current
32
33 " tab page
34
35 close
36
37 endif
38
39 endif
40
41 endif
42
43 endfunction

同时在vimrc中需要设置:
view sourceprint?
1 let Tlist_Exit_OnlyWindow=1


winmanager自带的fileexplorer这个插件实在是比较差。最重要的一点是fileexplorer不能自动更新,如果通过其他的途径修改了文件夹中的内容,fileexplorer是不会显示的。相对而言Nerd_Tree 功能就比较强大了。下面要把Nerd_Tree加入winmanager。

四、Nerd_tree:

下载解压,打开NERD_tree.vim,按照winmanager的说明,在最后加入下面代码:
view sourceprint?
01 "Used by winmanager {{{1
02
03 let g:NERDTree_title = "[NERDTree]"
04
05 function! NERDTree_Start()
06
07 exe 'NERDTree'
08
09 endfunction
10
11
12
13 function! NERDTree_IsValid()
14
15 return 1
16
17 endfunction

同时把在vimrc中:
view sourceprint?
1 let g:winManagerWindowLayout='NERDTree|TagList,BufExplorer'

原来的设置注释掉。加好后,发现每次打开winmanager都会出现一个空白的buffer。试验了好多次,但是Nerd_tree调用的函数就是会打开一个新窗口。因为如此,将bufExplorer和NERD_Tree放在一起会显示不正常。NERD_Tree放在下面的窗口也会出错,实在比较郁闷。。。。看了下NERD_Tree的代码,没看懂,只好再次改winmanager的代码了。

打开winmanager.vim,找到函数function! <SID>ToggleWindowsManager(),加入两行,修改后整个函数如下:




view sourceprint?
01 " toggle showing the explorer plugins.
02 function! <SID>ToggleWindowsManager()
03 if IsWinManagerVisible()
04 call s:CloseWindowsManager()
05 else
06 call s:StartWindowsManager()
07 " NERD_tree need this. 打开时会有一个空白窗口,要把他关闭。
08 exe '1wincmd w'
09 exe 'q'
10 end
11 endfunction



加个注释,以免以后忘掉了,如果不想用nerd_Tree了,这2句话还得删掉。



另外打开时的命令和关闭时的命令也得同时修改了,试验了很多次:

taglist.vim中,找到下面的代码:


view sourceprint?
1 " Exit Vim itself if only the taglist window is present (optional)
2 " if g:Tlist_Exit_OnlyWindow
3 " autocmd BufEnter __Tag_List__ nested
4 " \ call s:Tlist_Window_Exit_Only_Window()
5 " endif



将这段代码修改为:


view sourceprint?
01 " Exit Vim itself if only the taglist window is present (optional)
02 let s:NERDTreeBufName = 'NERD_tree_'
03 if g:Tlist_Exit_OnlyWindow
04 augroup Exit_onlywindow
05 "当进入Nerd_Tree的buffer时也检测是否需要退出
06 exec "autocmd BufEnter ". s:NERDTreeBufName .
07 \"* call s:Tlist_Window_Exit_Only_Window()"
08 autocmd BufEnter __Tag_List__ nested
09 \ call s:Tlist_Window_Exit_Only_Window()
10 augroup end
11 endif



winmanager中:刚才添加的自动执行命令要改为:


view sourceprint?
1 "set auto open Winmanager
2 if g:AutoOpenWinManager
3 " autocmd VimEnter * nested call s:StartWindowsManager()|1wincmd w
4 autocmd VimEnter * nested call s:StartWindowsManager()|1wincmd w|q
5 endif

这样所有的功能就实现了。在taglist窗口使用ctrl+n可以转换到bufexplorer窗口。  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: