When I click on a link in thunderbird and firefox is already running, it doesn't open a new window, just a new tab.
I want the same thing for vim: no matter where I am and how I send a bunch of files to it, I want them opened in a single session.
To do this, I've added the following code in my ~/.bashrc
and ~/.zshrc
.
function nv {
vim --serverlist | grep -q VIM
if [ $? -eq 0 ]; then
if [ $# -eq 0 ]; then
vim
else
vim --remote "$@"
fi
else
vim --servername vim "$@"
fi
}
It defines the function nv
which can do 3 things :
- if no VIM server is running,
nv
launches one - if a VIM server is
running and one or more arguments were passed to
nv
, it sends them to the server - if a VIM server is running but no argument was passed
to
nv
, it launches a simple vim session (so that I can still launch a separate vim session by using the same function / alias)
I've recently read that you could redirect the output of a shell command as the quickfix list to vim. For example :
vim -q <(grep -Rn foo *)
It works with vim but not with my function nv
.
I would like to use the same syntax so that the output of grep
is not opened by a new vim session, but by the VIM server.
When I use nv -q <(grep -Rn foo *)
, the VIM server doesn't receive the output of grep
but a file called -q
and another one : /proc/<pid>/fd/11
.
I know why it doesn't work, the function was not written with that case in mind.
But then, I tried something simpler : vim --remote -q <(grep -Rn foo *)
And the result is the same, it doesn't work, the server still receives two files : -q
and /proc/<pid>/fd/11
.
I would like to know if it's possible to edit the code of my nv
function so that it works when I use it with the -q
switch to remotely populate the quickfix list of an already running vim server, and if so receive some advice on how to do it.
If it's not, at least, I would like to know how to use the -q
and --remote
switch simultaneously.
Edit : I may be wrong but I don't think -q
and --remote
can be used simultaneously.
For the moment, I've come up with the following command :
vim --remote-send ":grep -Rn foo *<cr><cr>"
Now I need to edit the nv
function to integrate it, but I don't know how to do it.
Edit bis: I don't think it's worth the trouble, I'll stick with nv
and the last command when needed.
--remote
arguments, but you should get something to work, if in your function you check for the argument-q
and then use--remote-send ":cexpr $1<cr>"
or something like this. That should work, but as I said, I don't know for sure.