Вопрос

I want to search and replace some text in all php files in a folder using vim. One difficulty is that these files are all on a ftp site.

As far as I know this can be done (without ftp) as follows:

First open files in a buffer:

:args *.php

Then apply the search/replace over all files in the buffer

:argdo %s/<pattern1>/<pattern2>/ge | update

However, I'm not sure how to load all files in a directory using the vim ftp plugin. I tried:

:args ftp://user@website.com/dir/*.php

But this just 'opens' a new file called *.php on the specified ftp location. Any ideas?

If someone knows an alternative e.g. by using sed over ftp in Linux this would be fine as well.

Это было полезно?

Решение

Open the directory containing the files using netrw:

:e ftp://user@website.com/dir/<CR>

Note the trailing slash is important.

Now select all the files you're interested in, using a glob:

mr
*.php<CR>

This will mark all the files matching the pattern. Now you can add them to the arglist and work on them with argdo:

me

Press <F1> while in the netrw directory listing for help with the commands available.

Другие советы

Netrw, like every other editor's FTP plugin, downloads the remote file to a temporary location on your local machine for editing and uploads it back upon save.

If you are not comfortable with netrw, you could simply download that directory to your machine with an FTP client, do your g/re/p locally and reupload it back when you are done.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top