0

I make a file called run_gvim_thing.sh in my home dir. Inside of that is the command gvim myfile.py && echo "yay". If I run that file from terminal it launches gvim with myfile.py. If I run that file from ex mode it does nothing but echos "yay"

Why is this?

When logging gvim for errors I caught this:

Fatal Python error: Py_Initialize: can't initialize sys standard streams
OSError: [Errno 9] Bad file descriptor
  • I don't know why you'd need to start a new vim instance from vim: chances are you are solving a XY problem and you should use buffers and tabs. However you might be interested by this answer which suggests that maybe you could use :!start gvim in command line mode. – statox Jun 29 '17 at 7:42
  • I open a new window for each function that I work with, and I position the windows matching the call stack from left to right. I put tests below their files. I find it much more effective than tabs/buffers/splits when using a large screen. This workflow follows the LightTable ideas. I also have a plugin to open the function under the cursor in a new window which enhances the workflow a lot. – CornSmith Jun 29 '17 at 14:52
  • start is a windows only command. On OSX there's open but it doesn't handle args beyond the second one even with the --args command. It's frankly broken. However yesterday I did come up with a solution by running a python service with zmq and listening for commands and running them. I can pass it the gvim file.py command from vim and it'll open it. It's janky but it works. – CornSmith Jun 29 '17 at 14:54
  • 1
    I've made some more progress towards an actual fix though. I tried running this from gvim: :!gvim file.py &> error.log and I got this error in the output: Fatal Python error: Py_Initialize: can't initialize sys standard streams OSError: [Errno 9] Bad file descriptor Current thread 0x00007fffd35633c0 (most recent call first) Vim: Caught deadly signal ABRT Vim: Finished. – CornSmith Jun 30 '17 at 14:56
  • 1
    AND I found that if I comment out my vimrc's python related code (which I should have done to start with) it works as intended and I can open new gvim windows for days. So now this is narrowed down to a python problem. I'll continue after work today. – CornSmith Jun 30 '17 at 14:58
1

I put this at the top of the .vimrc to fix it. But instead of calling :!gvim some_file.py you need to call Runit('gvim some_file.py')

python3 << EOF
from multiprocessing import Process
import os

def worker(x):
  os.system(x) 

def do(x):
  Process(target=worker, args=(x,)).start()
EOF
function! Runit(command)
python3 << EOF
command = vim.eval('g:command')
do(command)
EOF
endfunction

After doing some error logging it was clear that the problem was something to do with python3 not releasing some file if called from a vim instance. So I thought maybe spawning a new python instance from vim and calling it from there would work, and it did.

Hopefully the MacVim people patch this up.

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.