views:

70

answers:

1

Sometimes I edit a file that represents a server restart. I would like to "bind" this restart to my vim session, so, after saving a file, it would call a bash script that would restart for me.

For example, calling :wapache automatically calls restart_apache.sh somewhere in my machine.

Is this possible? Is there a plugin that would organize these scripts inside .vim directory?

+4  A: 

You could presumably add something like the following to your vimrc:

autocmd BufWrite /etc/httpd/conf/* !restart_apache.sh

So that each time you save a file in the apache conf dir, vim executes your restart_apache.sh. You'd have to work out your permissions and what not.

I personally do not know of a script that manages these types of actions for you.

Randy Morris
It's a little more complex, that's why I want to understand the concept. I have a Plone project in /home/personal/cvs/PROJECTNAME. There's a Zope process (Python) running with this string (PROJECTNAME) attached. I would like to, after saving *.py files inside this PROJECTNAME hierarchy, call a script that restarts a process that has this same project name.
Somebody still uses you MS-DOS
Something like "autocmd BufWrite /home/personal/cvs/*/*.py !sh <afile>:p:h:t"? ":p:h:t" takes the name of the parent directory.
Jaime Soriano
@Jaime Soriano: it seens powerful, but I couldn't understand your line... :( Can you explain in details? Thanks for your suggestion tough...
Somebody still uses you MS-DOS
This line defines an automatic action to be executed on every write on files whose path matches with "/home/personal/cvs/*/*.py". The action is "!sh <afile>:p:h:t", that runs with sh the script with the name of the parent directory. ":p:h:t" are modifiers over the name of the saved file (<afile>), ":p:h" takes the full path of the directory and ":t" the tail (the last component). You can also check the documentation for that: http://vimdoc.sourceforge.net/htmldoc/cmdline.html#:_%:
Jaime Soriano
Thanks for the link and explanation, Jaime.
Somebody still uses you MS-DOS