0

I'm trying to setup separate configs for my WSL, Windows, and MSYS2 environments in the same init.vim with simple if-else statements. So, I'll need to know what environment I'm in. To know that I decided to declare a global variable in the following manner.

if !exists("g:env")
    if system('uname') =~ "msys"        " uname returns MSYS_NT-10.0-19041
        let g:env = "MSYS2"
    elseif has('windows')
        let g:env = "WIN"
    else
        let g:env = "LINUX"
    endif
endif

But when I start neovim from inside MSYS2, this block sets g:env equal to "WIN" for some reason.

Now, if I source the block (inside the if !exists block, obviously) after neovim has already booted up, then g:env is set to "MSYS2". So, maybe there is something going on at the startup?


NVIM v0.5.0
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe /DWIN32 /D_WINDOWS /W3 -DNVIM_TS_HAS_SET_MATCH_LIMIT /MD /Zi /O2 /Ob1 /DNDEBUG /W3 -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -DWIN32 -D_WIN32_WINNT=0x0600 -DINCLUDE_GENERATED_DECLARATIONS -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -ID:/a/neovim/neovim/build/config -ID:/a/neovim/neovim/src -ID:/a/neovim/neovim/nvim-deps/usr/include -ID:/a/neovim/neovim/build/src/nvim/auto -ID:/a/neovim/neovim/build/include
Compiled by runneradmin@fv-az152-786

Features: -acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM\sysinit.vim"
  fall-back for $VIM: "C:/Program Files/nvim/share/nvim"

Run :checkhealth for more info
1

Operator =~ will either ignore case or not depending on whether the 'ignorecase' option is set. You're trying to match a lowercase pattern, but the text you're matching contains an uppercase instance of the pattern. The 'ignorecase' option defaults to off, but is commonly set in one's init.vim, so I believe that's why you're getting different behavior during startup and after NeoVim is already running.

You can easily fix this by using the =~? operator instead, which will always ignore case, independent of whether the 'ignorecase' option is set or not.

if system('uname') =~? "msys"
1
  • Oh, right. Forgot about that.
    – klaus
    Sep 13 at 14:20

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.