1

I have a shared .vimrc that I use across platforms. It works fine in most circumstances, but looks terrible when I run git commit from the command line. I want to make my color scheme not load when run in that circumstance, but the conventional test for windows has("win32") fails in that environment! In fact, has("unix") is true in that environment!

Does anyone know what configuration of Vim is shipped with Git for Windows, and how to detect it?

8
  • 5
    Does this answer your question? Detect OS in Vimscript – Zoe Jun 9 at 15:55
  • See specifically the second answer – Zoe Jun 9 at 15:55
  • 2
    maybe check has("win32unix") or perhaps check some environment variables – Christian Brabandt Jun 9 at 15:55
  • 4
    I'm inclined to close based on @Zoe's comment, since one answer there specifically addresses this. Sean, if you can confirm/deny (an edit or comment is fine) that it answers your question, I'll do so. I'm holding off otherwise. – D. Ben Knoble Jun 9 at 16:59
  • 2
    @BLayer Right, my bad ^^" I never use any other sorting orders than votes - easy to forget it exists. I was referring to this one – Zoe Jun 10 at 19:36
2

EDIT: user Christian Brabandt points out that v:progpath will still only contain /usr/bin/vim when invoked through git-for-windows, so this solution will not work.


Maybe something along these lines?

if v:progpath =~ "git"
    colorscheme default
endif

The variable v:progpath should contain a path to the running vim executable, and (assuming that the version of vim that git commit spawns is included in your git installation) =~ "git" should detect whether that executable is within git's installation directory. (This is all very hypothetical of course)

According to help v:progpath:

v:progpath    Contains the command with which Vim was invoked, in a form
      that when passed to the shell will run the same Vim executable
      as the current one (if $PATH remains unchanged).
      Useful if you want to message a Vim server using a
      |--remote-expr|.
      To get the full path use: 
          echo exepath(v:progpath)
      If the command has a relative path it will be expanded to the
      full path, so that it still works after `:cd`. Thus starting
      "./vim" results in "/home/user/path/to/vim/src/vim".
      On Linux and other systems it will always be the full path.
      On Mac it may just be "vim" and using exepath() as mentioned
      above should be used to get the full path.
      On MS-Windows the executable may be called "vim.exe", but the
      ".exe" is not added to v:progpath.
      Read-only.
2
  • 1
    Welcome to Vi and Vim! This could benefit from some explanation, esp. the v:progpath variable (citing the help is fine!). For example, does v:progpath usually contain git when vim is started by git-commit on Windows? Is that reliable? – D. Ben Knoble Jun 10 at 18:08
  • v:progpath is the path to the actual running vim instance. In Git-For-Windows, this is something like /usr/bin/vim. It has nothing to do with git itself, just that git-for-windows packages vim along with many other POSIX like utilities. – Christian Brabandt Jun 11 at 8:41
1

A new angle of attack:

if has_key(environ(), "MINGW_PREFIX") && has_key(environ(), "GIT_INDEX_FILE")
    colorscheme default
endif

Poking around in help environ, it looks like has_key(environ(), <name>) is the recommended way of determining whether a system environment variable is defined. I'm not an expert on what variables will or won't exist during git commit, but MINGW_PREFIX looks like its an artifact of the unix compatibility layer git-for-windows uses (worth a google), and GIT_INDEX_FILE looks like its provided by git itself (per the docs). Again, highly theoretical, YMMV!

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