问题描述:

I'd like to open CtrlP if I am opening a directory with vim, but not a file. I like to have it automatically open in I just open a directory for convenience. However, it is slightly inconvenient if I know exactly which file I want to open because of the added loading time.

Currently I just have this in my .vimrc:

autocmd vimenter * CtrlP

Thanks in advance for any responses!

网友答案:

You can write a function to test the args to see if a single directory was passed in and if it was, execute CtrlP. Here is a very rudimentary solution:

function! MaybeCtrlP()
    if argc() == 1 && isdirectory(argv()[0])
        " Uncomment this to remove the Netrw buffer (optional)
        " execute "bdelete"
        execute "CtrlP"
    endif
endfunction

autocmd VimEnter * :call MaybeCtrlP()
网友答案:

In .bash_profile, create an alias:

alias vimCtrlP="vim +CtrlP"

Then every time you need this, use vimCtrlP as you would issue vim in shell, followed by the directory.

相关阅读:
Top