How to edit FTP files with VIM and avoid typing the hostname everytime?
Solution 1
You can use netrw to display the content of a remote directory with:
:e ftp://[email protected]/ <-- note the slash at the end.
from there you can open a file in another window with P
or in the current window with <CR>
.
Don't panic if you loose the file listing: it's still there and you can get it back with :Rex
.
Or simply use a GUI FTP client like Filezilla or gFTP and its "Edit in…" feature.
Solution 2
Though you cannot simple use relative filenames (because the local working directory is different), you can use the filename-modifiers to refer to files relatively:
:edit %:h/another.html
Solution 3
I know this is old, but another option is to use e.g. curlftpfs (Slackware build here) to mount the FTP server to a mount point, then use your local text editor of choice.
Related videos on Youtube
Keeper Hood
Updated on September 18, 2022Comments
-
Keeper Hood almost 2 years
I need to edit remote files with vim, that are on a FTP server. THere's no SSH or SFTP access. Just FTP. I've tried syncing via curlftpfs, the files appeared in a local dir, but i cannot write to them, i get all sorts of errors, and when i manage to write files with random endings are generated on the server. index.php writes on server as index.phz, index.phy, etc...
I had sublime text 2 installed but cannot run it anymore after i installed new drivers for my graphic card. I've also tried n++ with WINE but no luck in openeing FTP files that are in a deeper directory level.
I've seen there are various approaches with vim to edit files on the FTP, but every single one needs typing like :e http://[user@]machine/path (with netrw plugin). I would really like to avoid anykind of repetition, rather set up a relative mapping. It's strange that there's not solution for vim since its a developer's tool mostly, sublime and npp already have that solved in a simple manner. typing on and on the same hostname/path etc. would break a simple DRY principle.
Idealy would be if i could cache the files locally with some syncing tool, and upload them to ftp mapping the path local -> remote, right after vim writes to a file, or i issue an upload command etc (without having to type file opened every time). There are plenty of files on the server so i cannot memorize them, It's important for me to have them cached locally so that i can access them fast and upload with a simple command.
I'm running Slackware 13.37 x64
-
Keeper Hood over 11 yearsI've tried the vim and filezilla method, and the filezilla is much faster than the vim, however if i open more files many new vim windows just makes too much mess. Will give gFTP a try. I just wish i could run sublime again since it beats any of the other ancient methods which make me counter productive :(
-
romainl over 11 yearsgFTP works like Filezilla: the windows mess is Vim's fault. In both FTP clients, you need to set this command as "editor":
"/usr/bin/gvim" --servername filezilla --remote-tab
. -
romainl over 11 yearsWhy can't you run Sublime? It works very well on Linux.
-
Keeper Hood over 11 yearsIt did work, but I've updated some graphics drivers and it crashes on start now, don't wanna go into offtopic.
-
Keeper Hood over 11 yearsThe --remote-tab works much better, wondering how can i set the command to add a buffer instead of a tab if i need to? –
-
romainl over 11 yearsSee
:help clientserver
for all the options. You can use--remote
instead of--remote-tab
. -
Keeper Hood over 11 yearsI'll mark this question as answered since you gave me the most helpful information and it answers my public question. However I'm still struggling to find a way to use the same functionality and a fluent workflow of the sublime text editor in a vim environment on linux. thanks.