I am trying to use reverse searching from PDF documents to their respective *.tex files. I use vim (in terminal) as my editor and my PDF viewer is Zathura. Forward searching works however the problem with reverse searching is that vim requires a server name to be defined so that zathura can send it commands.
Is it possible to configure vim so that when running vim name.tex
in terminal it will automatically define a server name which is 'name'
? Essentially, I would like to make it so vim name.tex
runs as if I had input vim name.tex --servername name
. Is such a thing possible? I am aware that the server name cannot be defined once vim is running and needs to be part of the terminal command, however I am not experienced with this sort of thing.
EDIT: After some testing if I run vim --servername vim
in multiple terminals and then run vim --serverlist
in another I notice that all the servers have the name VIM followed by the number. So for example if I have four terminals open and run vim --servername vim
in each and open a fifth terminal and run vim --serverlist
it returns,
VIM
VIM1
VIM2
VIM3
With this if I have set synctex-editor-command 'vim --remote-silent +%{line} %{input}'
in my zathurarc
by <C-left click>
it will reverse search to the appropriate line of my TeX code in the server with lowest numbered VIM
servername. So if I close the server VIM
and the remaining servers VIM1
, VIM2
, and VIM3
are still open the the reverse search will bring up the TeX code in VIM1
. So essentially this simplifies the problem to just having a script which executes vim name.tex --servername vim
.
SOLUTION
This solution is due to statox and as such I have marked him as having solved it. I simply tinkered with his idea to get the final product. For any of those who pass and are in need of a solution in ~/.bashrc
place the following
alias vimsn='vim-with-servername'
vim-with-servername() {
vim --servername 'vim' "$@"
}
alias vim=vimsn
After doing this restart your terminal. Running vim file.type
in terminal will now run vim --servername vim file.type
.