Executing vi on directory does not list files

This seems like a new bug (feature ?) that’s creep into Ubuntu 13.10. When I execute vi on a directory it doesn't list the files which I can navigate to with the arrow keys; it just shows an empty screen with the message 'Illegal filename'.

Now it's an hassle because I have to ls the directory first if I don't know which file I want to edit and then I've got to type the entire file name after the directory in the command argument.

This happens when I go to vi the tmp, etc, and even in my home directory which I have write permission for.


Solution 1:

The behaviour you are describing is caused by a bug in netrw, which is the plugin handling the file browsing.

Updating to the latest version of the plugin fixes this behaviour.

To do so, just download the latest version of netrw, open it in vim and source it. Doing so will extract the plugin into your ~/.vim directory, where it will be loaded before the system's buggy version.

Download the file:

wget http://www.drchip.org/astronaut/vim/vbafiles/netrw.vba.gz

Open it in vim:

vim netrw.vba.gz

In vim, source it:

:so %

Afterwards, close vim. Then, enjoy browsing directories again.

Update: On one box, this gave me an error about not being able to close the last window. Had no effect on the plugin, which worked flawlessly afterwards.

2nd Update: This version of netrw expects a version of vim with the clipboard capability.

You can check if your version has it by running vim --version. The output will probably have -clipboard in there, which means the capability is not enabled.

To get a version compiled with clipboard support, install any version of vim with a GUI, which will also replace your normal vim with a version with clipboard support. I used vim-gtk as a test case.

Solution 2:

I tried following the steps given by drc, but got strange errors (perhaps due to lack of clipboard support).

The following worked for me in ubuntu 13.10 docker image, with just a standard version of Vim without clipboard support:

vim /etc   # blank screen

wget http://www.vim.org/scripts/download_script.php?src_id=21427 -O netrw.vba.gz

# install the vimball
# may throw error E444, but this can seemingly can be ignored
vim netrw.vba.gz +"so %" +q  

vim /etc  # works fine

Note that the only thing that I did differently than drc involved me using a slightly older release of the netrw plugin, namely the one uploaded to vim.org on 2014-02-04.