I am transitioning from using Gvim to console Vim.
I open a file in Vim, and then suspend Vim, run a few commands on the command-line and then want to return to Vim.
Ctrl+Z
(in normal mode) suspends Vim and drops back to the consolefg
can be used to return focus to Vim jobs
lists background jobs and can be used to get the job number to
bring a given job to the foreground (e.g., fg %2
to bring job 2 to the
foreground).However, when Vim is in the background and I issue vim file
, the file opens in a new instance of Vim.
I'm used to using the --remote
option with Gvim to open a file in an existing Gvim instance.
I just read this answer by @jamessan which provides a few ideas. He shows the following code snippet:
vim --servername foo somefile.txt
:shell
<do stuff in your shell>
vim --servername foo --remote otherfile.txt
fg
However, I'd have to think about how to make it easier to use perhaps with some aliases.
This is also what I need. I found this thread, though no satisfying approach, happy to see people having same requirement like me.
My approach is
v() {
vim_id=`jobs|sed -n "/vim/s/\[\([0-9]\)\]+.*/\1/p"`
if [ -n "$vim_id" ]; then
echo "tabedit $@" > ~/.vim_swap/e.vim && fg $vim_id
else
vim $@
fi
}
nnoremap <silent> <space>e :source $HOME/.vim_swap/e.vim<Bar>:call writefile([], $HOME."/.vim_swap/e.vim")<CR>
Then v foo.c
to open first file, editing..., ctrl-z to suspend vim, do shell stuff, v bar.h
to bring vim foreground.
And in VIM, press <Space>e
to tabedit bar.h.
So the idea is to generate vim command from shell command, save them to a temp .vim file. In VIM, map key to source the .vim file and clear it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With