I have a hotkey in Vim that takes me into command mode and calls a Bash script. The Bash script attempts the following steps:
- Select text between two tokens
- Send selected text block to a .py file
- Load the .py file into IPython
The script works if I type everything in by hand, but if I run the script, the text block is not saved as a file until after the script is finished, causing an error when IPython tries to load the file later in the script.
Here are the steps I've tried:
- In the event my file is being held in the buffer, I tried syncing and flushing
- In case the file needed more time to be written, I tried sleep and wait
- I also tried asynchronous shell commands to see if the Bash script was getting priority over Vim writing the file.
#!/bin/bash
# Text to be written has been selected in Vim
tmux send-keys ':w jtemp.py'
tmux send-keys 'Enter'
# Load code selection in IPython
tmux select-pane -t 1
tmux send-keys '%load jtemp.py'
tmux send-keys 'Enter'
tmux send-keys 'Enter'
How can I get the file to be saved to disk while the Bash script is still in process?