Automatically run script when exiting vim?
bash, vim
Solution
Thank you to those of you who suggested autocmd events. The events that I have found to be most appropriate are BufWinEnter and BufWinLeave. Here's exactly what I put in my vim:
:autocmd BufWinEnter * !clock_edit %:p
:autocmd BufWinLeave * !clock_close %:p
clock_edit bash script:
#!/bin/bash
echo "`date`:: opened file $1" >> ~/.clock_log
clock_close:
#!/bin/bash
echo "`date`:: closed file $1" >> ~/.
For example, when I open `config.txt`, vim will invoke `clock_edit /node/proj/config.txt`. If I open several files as tabs, each one I open will invoke clock_open and each one I close will invoke clock_close, with the appropriate filename and path passed as arguments. Even better, it doesn't repeat the process when I switch tabs or window focus, just when I open and close the files.
Thank you for all your help!
edit: autocmd is a useful way of binding vim commands to events ( such as saving a file ) in vim. For more info, read about autocmd here.
Problem
I'm trying to keep track of my hours for work, and I have to keep very specific details of which files I was editing and when. In my .vimrc script, I have: ``` :silent !clock_in_script.sh %:p ``` This clock_in_script.sh takes the location of the file as an argument and just writes the name of the file and time to a log. Is there a way to similarly invoke a script when I exit vim? If not, is there a way I can write the name of the file I'm editing and the time to a logfile from vim? Thank you in advance!