New

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            21 Posts :: 0 Stories :: 4 Comments :: 0 Trackbacks
          _vimrc  

          如果文件格式為java則使用indent/java.vim的縮進規(guī)則

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

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

          設(shè)置Tlist

          let Tlist_Show_One_File=1
          let Tlist_Exit_OnlyWindow=1  Tlist是最后一個窗口關(guān)閉時退出

          設(shè)置winmanager

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

          設(shè)置鍵盤映射


          nmap wm :WMToggle<cr>


          posted on 2011-10-31 22:22 H.C 閱讀(4154) 評論(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>
            回復(fù)  更多評論
            

          # 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。

          設(shè)置一下環(huán)境變量。path=D:\ctags58。這樣可以直接運行目錄下面的ctags.exe文件。或者直接把ctags.exe放入windows的目錄里。

          vimrc中的設(shè)置:
          view sourceprint?
          1 "生成一個tags文件
          2 nmap <F9> <Esc>:!ctags -R *<CR>



          二、taglist設(shè)置:

          下載解壓到相應(yīng)的vim文件夾中。

          vimrc中設(shè)置:
          view sourceprint?
          01 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
          02
          03 "設(shè)置Taglist
          04
          05 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
          06
          07 " 這項必須設(shè)定,否則出錯,配置taglist的ctags路徑
          08
          09 let Tlist_Ctags_Cmd = 'D:\ctags58\ctags.exe'
          10
          11
          12
          13 " 不同時顯示多個文件的 tag ,只顯示當(dāng)前文件的
          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 "讓當(dāng)前不被編輯的文件的方法列表自動折疊起來
          26
          27 let Tlist_File_Fold_Auto_Close=1
          28
          29
          30
          31 "把taglist窗口放在屏幕的右側(cè),缺省在左側(cè)
          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

          啟動自動打開這個選項暫時不設(shè)置。后面要讓winmanager調(diào)用taglist。



          三、bufexplorer:

          下載解壓,沒啥說的。



          四、winmanager:

          下載解壓,vimrc中的設(shè)置:
          view sourceprint?
          01 """""""""""""""""""""""""""""""
          02
          03 "" winManager setting
          04
          05 """""""""""""""""""""""""""""""
          06
          07 "設(shè)置界面分割
          08
          09 "let g:winManagerWindowLayout = "BufExplorer,FileExplorer|TagList"
          10
          11 let g:winManagerWindowLayout = "TagList|FileExplorer,BufExplorer"
          12
          13
          14
          15 "設(shè)置winmanager的寬度,默認(rèn)為25
          16
          17 let g:winManagerWidth = 30
          18
          19
          20
          21 "定義打開關(guān)閉winmanager按鍵
          22
          23 nmap <silent> <F8> :WMToggle<cr>



          以上3個插件安裝設(shè)置完畢后,基本的界面功能就可以實現(xiàn)了。按F8可以打開/關(guān)閉界面。同時顯示taglist和fileexplorer。在fileexplorer窗口中按<c-n>可以切換到bufexplorer窗口。

          上述設(shè)置好后,有3個問題:

          1 我想讓插件顯示在右側(cè),但是winmanager里面沒有此選項

          2 進入vim時候不能自動打開winmanager,winmanager不像taglist支持該功能

          3 退出時不會像只有taglist時候那樣,退出當(dāng)前文件就會退出vim了

          經(jīng)過多次修改代碼終于實在了上述3個功能。



          五、將插件顯示在右側(cè)

          打開winmanager.vim,在function! <SID>StartWindowsManager()函數(shù)中修改:

          將: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中設(shè)置:
          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



          七、退出緩沖區(qū)時,自動退出vim

          這個功能是參考了taglist的自動退出功能,在taglist.vim中修改的。

          函數(shù):function! s:Tlist_Window_Exit_Only_Window()中的winbunr(2)改為winbunr(3),即只剩2個窗口時關(guān)閉,考慮到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中需要設(shè)置:
          view sourceprint?
          1 let Tlist_Exit_OnlyWindow=1


          winmanager自帶的fileexplorer這個插件實在是比較差。最重要的一點是fileexplorer不能自動更新,如果通過其他的途徑修改了文件夾中的內(nèi)容,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'

          原來的設(shè)置注釋掉。加好后,發(fā)現(xiàn)每次打開winmanager都會出現(xiàn)一個空白的buffer。試驗了好多次,但是Nerd_tree調(diào)用的函數(shù)就是會打開一個新窗口。因為如此,將bufExplorer和NERD_Tree放在一起會顯示不正常。NERD_Tree放在下面的窗口也會出錯,實在比較郁悶。。。。看了下NERD_Tree的代碼,沒看懂,只好再次改winmanager的代碼了。

          打開winmanager.vim,找到函數(shù)function! <SID>ToggleWindowsManager(),加入兩行,修改后整個函數(shù)如下:




          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. 打開時會有一個空白窗口,要把他關(guān)閉。
          08 exe '1wincmd w'
          09 exe 'q'
          10 end
          11 endfunction



          加個注釋,以免以后忘掉了,如果不想用nerd_Tree了,這2句話還得刪掉。



          另外打開時的命令和關(guān)閉時的命令也得同時修改了,試驗了很多次:

          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 "當(dāng)進入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中:剛才添加的自動執(zhí)行命令要改為:


          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

          這樣所有的功能就實現(xiàn)了。在taglist窗口使用ctrl+n可以轉(zhuǎn)換到bufexplorer窗口。  回復(fù)  更多評論
            


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 穆棱市| 湛江市| 旌德县| 城口县| 龙江县| 当阳市| 绵竹市| 乌拉特后旗| 烟台市| 蒙自县| 泗水县| 科尔| 敦煌市| 繁昌县| 桂东县| 广宁县| 资源县| 革吉县| 遵义县| 盐亭县| 沂南县| 晋州市| 奎屯市| 南郑县| 蕲春县| 津南区| 定安县| 依兰县| 夹江县| 右玉县| 贵州省| 安塞县| 将乐县| 印江| 铜鼓县| 衡南县| 武山县| 麻江县| 澄江县| 昌吉市| 长岭县|