is it possible to specify vim servername in .vimrc, or somewhere else, according to filetype?

StackOverflow https://stackoverflow.com/questions/13178335

  •  25-07-2021
  •  | 
  •  

Domanda

I have to type

gvim --servername xdvi toto.tex

to enable inverse search from xdvi to latex.

Is there a way to encapsulate this in .vimrc: when vim detects the .tex file, an autocmd sets the servername to vimrc ? It seems it is too late once vim is launched, or?

If not in .vimrc, where ?

È stato utile?

Soluzione

The special v:servername variable is read-only; you cannot change it from within Vim. If you need a certain servername, that has to be specified on startup via the --servername argument.

To avoid the additional typing, I would suggest a special shell alias (on Unix) or small batch wrapper (on Windows). Depending on how crucial this is, you could even add some scripting logic to check for .tex arguments, and only then set the servername.

The only way to achieve this from within Vim would be forking a new instance of Vim (via system()), passing all arguments plus the servername argument, and then closing the original Vim instance via :quit. But that's very cumbersome and not as simple to implement.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top