Setting servername in vimrc as opposed to command line switch

Viewed 2030

Is it possible to set vim's servername from my vimrc instead of using the --servername command line switch? If I try one of

set v:servername="TEX"
let v:servername="TEX"

I get unknown option error and cannot overwrite read-only variable error respectively.

2 Answers

For a sufficiently new of vim there's the function remote_startserver.

                    *remote_startserver()* *E941* *E942*
remote_startserver({name})
        Become the server {name}.  This fails if already running as a
        server, when |v:servername| is not empty.

        Can also be used as a |method|: >
            ServerName()->remote_startserver()

Available since Vim version 8.0.475. according to VimTeX documentation

So you can simply start vim with no servername and start one in vimrc.

Note: Vim will automatically change the servername (append 1, 2, etc.) to avoid conflict if there are multiple running Vim instances.

Related