7

My .vimrc does a lot of extra things I don't want to do if it's launched by git (for example, during commit), since the purpose of that Vim instance is very specific so it makes no sense to launch many windows I would launch in normal way.

Is there any way I can detect whether this instance is launched by git?

5
  • 2
    For the specific case of commits, the FileType is gitcommit. You can probably use an autocmd based on that.
    – muru
    Aug 15, 2015 at 6:31
  • 4
    git also adds a number of variables to the environment, so you could test for the existence of one of those variables to determine whether Vim was launched from git. E.g., if exists("$GIT_DIR").
    – garyjohn
    Aug 15, 2015 at 7:54
  • 2
    @muru That should really be an answer! Nice orthogonal alternatives :) Aug 15, 2015 at 11:28
  • Are you saying that you automatically open multiple windows every time you launch Vim? Why do you do that? Aug 16, 2015 at 17:23
  • 1
    @KyleStrand I launch nerdtree for example. since i almost always want it to be there
    – Jason Hu
    Aug 16, 2015 at 19:25

1 Answer 1

7
$ git config --global core.editor "vim -Nu NONE"

tells Git to use Vim without sourcing your vimrc (-u NONE) and in "nocompatible" mode (-N).

And, well… you could even add something to start directly in insert mode:

$ git config --global core.editor "vim -Nu NONE -c startinsert"
5
  • wow, vim is too rich to learn.
    – Jason Hu
    Aug 15, 2015 at 12:46
  • 1
    Do we need --noplugin with -u NONE?
    – muru
    Aug 15, 2015 at 14:31
  • 2
    @muru, I could swear it was needed at some point but… not anymore. Whatever, let me edit my answer.
    – romainl
    Aug 15, 2015 at 15:16
  • Why do you think its no longer needed? The way plugins are loaded hasn't changed in many years. Aug 16, 2015 at 11:19
  • @SatoKatsura, I seem to remember a situation where netrw was loaded even with -u NONE. Maybe my memory is flawed. Maybe something else was messing with my setup at the time…
    – romainl
    Aug 16, 2015 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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