If you launch your first Vim session with the argument --servername VIM
:
$ vim --servername VIM
then you can send any command from any other shell with the argument --remote-send
.
For example, if you use your statusline to display the value of some variable g:myvar
, and you have the following lines in your vimrc:
let g:myvar = "foo"
set stl+=%{g:myvar}
Then you can change its value (:let g:myvar = "bar"
) from another shell:
$ vim --remote-send ':let g:myvar = "bar"<cr>'
The statusline should reflect the change of the value.
As your last comment says it, if your Vim instance is not in normal mode, the previous command will not work as expected. There may be simpler, but here are 2 possible solutions:
1) add the key <esc>
to be in normal mode
2) use the argument --remote-expr
instead of --remote-send
to evaluate an expression and write a small helper function whose code will assign the new value to your variable
First solution:
$ vim --remote-send '<esc>:let g:myvar = "bar"<cr>'
Second solution:
Define the following function in your vimrc:
function! Myfunc(value)
let g:myvar = a:value
endfunction
Then, in your shell:
$ vim --remote-expr 'Myfunc("bar")'