0

Here is an excerpt of my vimrc

let g:conda_activate = 'myenv'

function Condaenv(env)
    return trim(system("conda activate ". a:env. " && call echo %CONDA_DEFAULT_ENV%"))
endfunction

augroup Condaenvget
    autocmd!
    autocmd VimEnter * let g:conda_env = Condaenv(g:conda_activate)
augroup END

let g:airline_section_b = airline#section#create(['(%{g:conda_env})'])

As you see, I am using vim_airline plugin to manage the statusline but I don't think this is relevant to my problem that I am going to explain next.

I get the error Could not find conda environment myenv^@ on my status line. This is an error that you get when you run conda activate env from cmd.exe but env does not exist.

Therefore, I think the issue is in the function Condaenv. It looks like that the value of the variable a:env is 'myenv^@' instead of 'myenv'. I tried to use trim(system("conda activate ". trim(a:env). " && call echo %CONDA_DEFAULT_ENV%")) but with no success. I am running gvim 9.0 on Windows10 if it may help.

Any hints?

5
  • To some extent. It was actually me asking that question and the problem was solved using trim(system("conda activate ". a:env. " && call echo %CONDA_DEFAULT_ENV%")). Now, it is few days that this solution is not working any longer (I don’t know for what misterious reason given that I havent touched the vimrc since then), and the problem now is not in the returned string by trim but in the argument a:env inside system().
    – Barzi2001
    Nov 10, 2022 at 17:55
  • I know, that's why I was looking your other question up. And in the question, we discussed a few other ways to solve the way to get rid of the ^M (e.g. using systemlist()). And I still think, it does not make to have this command executed very often (each the statusline is re-evaluated). This will make your vim slow. Nov 10, 2022 at 18:33
  • Yeah, in-fact I am planning to try with systemlist but I am too tired now, so I will try tomorrow morning. Regarding the last part I didn’t get your point last time, nor now :) the event that triggers the call to Condaenv function is VimEnter, so in my understanding it happens once. Once the variable g:conda_env is written it won’t be updated any longer. At this least this is my understanding in looking at my code. But if I misunderstood something, please explain, I am all ears :)
    – Barzi2001
    Nov 10, 2022 at 19:09
  • I have finally found some time to make some test. systemlist has problems too but after some troubleshooting here is what I found: if I run :!conda list --envs from vim I get what you see from the first picture here, which looks weird. By running the command C:\WINDOWS\system32\cmd.exe /c (conda info --envs) after having opened cmd.exe in Windows, I get the (correct) second picture of the link I provided above. It looks like that something goes wrong when calling cmd.exe commands from Vim by using :!.
    – Barzi2001
    Nov 16, 2022 at 12:13
  • Given that the problem seems different, I am closing this question and I opened another one here: vi.stackexchange.com/questions/39304/…
    – Barzi2001
    Nov 22, 2022 at 7:40

0

Browse other questions tagged or ask your own question.