5

I'm on Ubuntu 16.04 (x86_64) and vim 7.4. In my config file, I have:

set autochdir

And this was working for as long as I remember. Just after upgrading to Ubuntu 16.04, I see the following behavior (assume pwd is /path):

  • The following commands (z is a file):

    $ vim X/Y/z
    :e .
    

    result in vim showing the contents of /path.

  • The following commands:

    $ vim X/Y/z
    :sp .
    

    result in vim showing the contents of /path/X/Y.

  • The following commands:

    $ vim X/Y/z
    :sp .
    :q
    :e .
    

    also result in vim showing the contents of /path/X/Y.

The expected behavior for me was for all three cases to open /path/X/Y. But it seems like :sp is changing the current directory, but :e is not. Before my upgrade to Ubuntu 16.04, I am sure all three cases did the same thing (open /path/X/Y).

Can anybody else reproduce this? Is this intended behavior and documented?


Additionally, if I do:

$ vim X/Y/z
:sp ./<TAB>          --or--
:e ./<TAB>           --or--
:w ./<TAB>

then vim iterates through the items in the X directory, not X/Y. Although if I do :sp ./X/w where X and w were selected using <TAB> (i.e. vim finds the items based on the current directory), the file is not actually opened (an empty new file is opened, as if the file doesn't exist). This suggests that autochdir has worked where opening the file is concerned, but hasn't worked where listing directory items is concerned.

5
  • I had same problem i just mapped nnoremap <Leader>e :e <C-R>=expand('%:p:h') . '/'<CR> To get around it
    – byaruhaf
    Commented Apr 22, 2016 at 14:47
  • :e filename respects autochdir but :e directory starts the netrw plugin which doesn't respect autochdir by default. See :help netrw for a solution.
    – romainl
    Commented Apr 22, 2016 at 16:26
  • @romainl, interesting. Although :help netrw doesn't really offer a solution.
    – Shahbaz
    Commented Apr 22, 2016 at 18:43
  • @romainl, by the way, how is it that before Ubuntu 16.04 I never had this problem, even though I was still using vim 7.4?
    – Shahbaz
    Commented Apr 25, 2016 at 14:14
  • @romainl please see my edit. The issue seems to be deeper than that.
    – Shahbaz
    Commented Apr 25, 2016 at 14:17

2 Answers 2

5

This appears to be an issue that was introduced in a patch that was picked up by Ubuntu 16.04 and fixed in another patch. Here's a link to the bug report. It was fixed in patch 1716 but, unfortunately, 16.04 shipped with patches only up to 1689.

Hopefully there'll be an update soon. Otherwise it's compile the latest version from source, I'm afraid.

2
  • Thanks for looking into it. It's a hell of an annoying issue, so I certainly hope Ubuntu picks up the fix.
    – Shahbaz
    Commented May 22, 2016 at 16:21
  • 1
    @Shahbaz There's pi-rho's PPA if you don't want to wait.
    – muru
    Commented May 22, 2016 at 23:59
2

I added this to my .vimrc and now it works as desired:

" Automatically set current directory to browsing directory.                                                      
let g:netrw_keepdir=0 

For more information: http://vimdoc.sourceforge.net/htmldoc/pi_netrw.html#g:netrw_keepdir

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.