0

Is there a way to disable a plugin only on occasions where Vim was launched from another program?

I have set Vim (Neovim, more specifically) to be the default core.editor of my git configuration and let's say I have these plugins in my .vimrc loading through vim-plug:

" Plugins to load with Vim
call plug#begin('~/.vim/plugged')

    Plug 'preservim/nerdtree' | Plug 'Xuyuanp/nerdtree-git-plugin'
    Plug 'itchyny/lightline.vim'
    Plug 'ryanoasis/vim-devicons'

call plug#end()

" Some variables and vimscripts directly related to a plugin
let NERDTreeShowHidden = 1

autocmd VimEnter * NERDTree | wincmd p
autocmd BufWinEnter * if getcmdwintype() == '' | silent NERDTreeMirror | endif

In this case, I just want to have a clean buffer ready for me to insert the commit message, so is it possible to make Vim ignore some of these plugins when commiting?


In other words:

  • Is Vim capable of understanding that it was launched through git commit (or merely git)?
  • Should it be capable, how must I change my .vimrc (either on the example above where the plugins are called or somewhere else in the file) in order to disable plugins I don't need?
    • In this case, anything related to NERDTree is irrelevant when commiting, so nerdtree, nerdtree-git-plugin and vim-devicons should be disabled while lightline.vim will keep getting loaded;
  • In case I manage to disable plugins under these circumstances, should I be aware of any further changes in variables and scripts that call upon these disabled plugins (such as the ones shown above)?
2
  • Would it be acceptable if NERDTree loaded but didn't start? That would make the problem slightly easier.
    – Heptite
    Jun 25 at 15:47
  • @Heptite, sure, no problem! Jun 25 at 15:49

1 Answer 1

2

git sets a number of environmental variables when invoked, if they're not already set in the environment. I would just test for one of those and conditionally run the NERDTree commands accordingly.

if !exists('$GIT_EXEC_PATH')
    autocmd VimEnter * NERDTree | wincmd p
    autocmd BufWinEnter * if getcmdwintype() == '' | silent NERDTreeMirror | endif
endif
2
  • Vim also sets the gitcommit filetype, so you can also use if filetype != 'gitcommit' [..] endif. Jun 26 at 14:34
  • @MartinTournoij nit &filetype, and there's also argv() and v:argv for testing the arguments.
    – D. Ben Knoble
    Jun 27 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.