5

This question is a follow-up to Switching to the local directory after loading a file?

I have the following in my .vimrc:

autocmd BufReadPost *.tex lchdir %:p:h

with the intent of setting the current directory to the same as the edited file for *.tex files, without setting the global autochdir.

It works if I call:

 gvim /home/romano/education/IntroEle-SAP-135/Lab-T1/LabTestExample.tex

Look at the full filename in status line here:

Working autocmd lchdir

But it does not work if I call:

gvim --servername desktop_0 --remote-tab-silent /home/romano/education/IntroEle-SAP-135/Lab-T1/LabTestExample.tex

Screenshot:

Not working autocmd

(the culprit seems to be the --remote-tab-silent switch). How can I correct this so that the autocmd works in the two cases?

4
  • 1
    Four years old and no responses...
    – muru
    Commented Feb 20, 2015 at 20:41
  • So seems a bug... where is the main bug report site for vim? Searched here vim.org but just found mailing lists...
    – Rmano
    Commented Feb 20, 2015 at 21:17
  • Looking around in that mailing list, I think it's on Google Code: code.google.com/p/vim/issues/list
    – muru
    Commented Feb 20, 2015 at 21:18
  • I'm not sure if it's a bug, or expected behaviour (but it could very well be one!) I need to carefuly read the remote server & autocmd pages to be sure... You can use :help bug-reports for information on how to report them. Commented Feb 20, 2015 at 22:19

1 Answer 1

1

I found a half workaround. The trick is that if you use --remote-send instead of --remote you can make all the autocmd working.

So I subsituted

gvim --servername $desktop --remote-tab-silent "$file"

with

 gvim --servername $desktop --remote-send "<ESC>:tabe $file<CR><CR>"

...and the autocmd works now. <ESC> is needed because the instance can be in input mode (annoyingly beeps if not) and the double <CR> is needed because otherwise vim is asking me to press a key --- I do not know why. Now, this do not work if $file has spaces in it; but this is OT here I think. Or maybe another question.

Now, there is no --remote-send-silent option do my script for double clicking on a file in nautilus and have it opened in the existing desktop-local gvim instance or open a new one has got a bit more complex (if anyone want to see it I can post it here, but it seems a bit OT).

3
  • 1
    I had this problem too and worked around it by using BufReadPost,BufEnter,BufWinEnter, but it still appeared sometimes. Thanks to this note on --remote-send I was able to find a reason of such behaviour, see this vim-dev post. So maybe it will be fixed in Vim soon. Another temporary half workaround is to set 'autochdir' option, if you're fine with changing directory for all filetypes.
    – xaizek
    Commented Mar 1, 2015 at 8:35
  • @xaizek thanks --- this is clearly the case for the behavior descried here. I have a workaround in the linked post --- I do not like autochdir for all files (even for TeX files, I do want the switch only for .tex, not for example .sty...)
    – Rmano
    Commented Mar 1, 2015 at 10:03
  • 1
    The patch has been accepted as 7.4.678.
    – xaizek
    Commented Mar 24, 2015 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.