Search code examples
vimftpnetrw

How can I change to a different directory on an FTP server in Vim?


Vim has a fancy NetRW plugin that lets me type

vim ftp://ftp.example.com/

And get a nice directory listing, which I can edit files from by simply pressing CR while on top of them.

However, I can't seem to do this with directories. In the help file that appears when I press F1, it says I should be able to:

BROWSING                                                netrw-cr {{{2

Browsing is simple: move the cursor onto a file or directory of interest.
Hitting the <cr> (the return key) will select the file or directory.
Directories will themselves be listed, and files will be opened using the
protocol given in the original read request.

However, when I use j/k to navigate to a directory and press <cr> to try to open it, I just get:

somedirectory: Not a regular file

Vim tries to access ftp://ftp.example.com/somedirectory. Notice that it doesn't add the slash signifying that it's a directory.

I'm at a loss for why this occurs. How can I simply enter that directory within Vim, without having to exit Vim and retype vim ftp://ftp.example.com/somedirectory/?

I'm running Vim 7.4 on Ubuntu 14.04.


Solution

  • Vim didn't seem to know that my directory really was a directory, as it didn't show a / sign after it in the directory listing.

    Luckily, I found a way to force NetRW to act like a file is a directory: gd.

    FORCING TREATMENT AS A FILE OR DIRECTORY        netrw-gd netrw-gf {{{2
    
    Remote symbolic links (ie. those listed via ssh or ftp) are problematic
    in that it is difficult to tell whether they link to a file or to a
    directory.
    
    To force treatment as a file: use
            gf
    
    To force treatment as a directory: use
            gd
    

    So, simply press gd instead of <cr> to change to the directory under the cursor.

    I'm still not sure why NetRW thought my directory was a file. The help message only said "remote symbolic links," which they're not (I think). It may have something to do with my web host (iPage), which might be using symbolic links everywhere instead of actual directories. Or maybe something just borked on my end.