Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically run script when exiting vim?

Tags:

bash

vim

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!

like image 801
James M. Lay Avatar asked Dec 04 '13 21:12

James M. Lay


Video Answer


1 Answers

there is an event VimLeave (:h VimLeave) is for the requirement you described.

However, this may not work for your needs. Because you may open many files in one vim instance. I use vim always in this way. In this case, you can only save the status of current buffer/file.

You can :h event to check out the events vim's autocommand supports. Also consider to write a small function to loop all buffers and call your command. or modify your shell script to accept more than one filename as parameter, so that you can call the script only once.

like image 163
Kent Avatar answered Oct 15 '22 00:10

Kent