This might be better for super user, but I figure as a tool of the trade it might be a better topic for here. I find often when editing in vim that I exit out, run some script that I am testing, and then go back into vim (yes I realize I can use :!command to run things from vim) I was just wondering if there is a way to hook something to run when the file is saved (:w)?

link|improve this question

feedback

3 Answers

up vote 2 down vote accepted

You might find incron of interest if you're using Linux.

link|improve this answer
feedback

See :he :autocmd and :he BufWritePost

The line would look like this:

:autocmd BufWritePost /path/to/file/or/pattern !command <afile>

If the <afile> thing does not work use %:p.

link|improve this answer
feedback

I got the "getting back to vim" part, but I'm not sure how to hit the ":w" command itself (which would be very handy, since that's quite reflexive for me)

w | silent execute "! myscript" | redraw!

I think it may be better for superuser as well.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.