I'm using exists() to check if plugins are installed i开发者_开发问答n Vim (I mapped ; to :):
if exists(":NERDTree")
map <F4> ;NERDTreeToggle<CR>
endif
The mapping doesn't work unless I source the .vimrc file manually. I'm using Pathogen to load my plugins on startup, I imagine that has something to do with it?
My complete .vimrc file: https://github.com/ElbertF/dotfiles/blob/master/.vimrc
Your call to exists() doesn't work because plugins are only loaded after vim has finished processing your .vimrc - see :help startup. Also, pathogen doesn't actually load your plugins, it merely adds their containing folders to the runtimepath option so they will be loaded after your .vimrc.
You could create a VimEnter autocmd to set up your mapping after vim has finished loading:
autocmd VimEnter * if exists(":NERDTree") | exe "map <F4> ;NERDTreeToggle\<CR>" | endif
In the MacVim you can define some mappings in the .gvimrc file, which parsed after the .vimrc. It is useful to redefine GUI Menu commands such as File → Open... or File → Save.
Here is example of the .gvimrc file which redefines Command+o hotkey to open NERDTree:
if has('gui_running')
if exists(':NERDTree')
" Command+O shows the NERDTree instead of the open dialog
macm File.Open\.\.\. key=<nop>
nnoremap <D-o> :NERDTree<CR>
inoremap <D-o> <Esc>:NERDTree<CR>
vnoremap <D-o> <Esc>:NERDTree<CR>
endif
endif
Where macm File.Open\.\.\. key=<nop> command unbinds any hotkey from the menu item File → Open.
And ?noremap <D-o> ... commands binds Command+o to show the NERDTree in the normal/insert/visual modes.
加载中,请稍侯......
精彩评论