This is a read-only archive!

Stupid Vim trick (and mental illness)

The OS on my first computer was Windows 3.1, and I lived with Windows 95/98/ME for a long time. When you live their formative years in this kind of environment, you develop an obsessive need to save your work all the time, because at any moment, the program you were using could crash. With Vim, a save is just a :w away. I hit that combination so often it's a wonder I haven't worn a hole through my w key yet. It takes no effort or thinking at this point, just a quick reflex flick of the wrist.

Did you ever wonder just how often you save your work in a given day? I wondered, so I put this into ~/.vimrc:

cabbrev w <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'W' : 'w')<CR>
command! -nargs=* W :execute("silent !echo " . strftime("%Y-%m-%d %H:%M:%S") . " >> ~/timestamps")|w <args>

Now every time I do :w, it will append a timestamp to a text file. It's not quite perfect and :w won't work right in certain cases but it was good enough for a quick hack.

I let Vim go like this for one whole day at work. I got in a good six and a half hours of coding on Tuesday (keeping in mind that I was using other programs all day too, messing with our DB, running and debugging the script I was writing, responding to emails, and so on).

It turns out I hit :w 356 times that day. Here's a chart of saves per hour.

Saves per hour

Clearly either my productivity or my data-loss paranoia increases as the day progresses. I think I got up to make a cup of tea at around 2:00 so that may explain the fall-off. And the last hour isn't quite a full hour of work because I went home.

So as a rough estimate, it looks like I save my work about once per minute. Looking at the data, it's not at all uncommon for me to have saved my work twice within a 5-second period of time. There are even a few cases where I saved twice within two seconds.

July 10, 2008 @ 9:48 AM PDT
Cateogory: Programming


Quoth foo on July 10, 2008 @ 12:09 PM PDT

This is a great idea! I'm going to try this tomorrow at work.

Michael Klier
Quoth Michael Klier on July 10, 2008 @ 6:03 PM PDT

Nice :-). I am going to try this as well. I noticed that I begin to hit :w often when I am thinking, three or four times in a row. That of course doesn't make any sense, it's sort of just giving my fingers something to do.

Quoth numerodix on July 10, 2008 @ 6:56 PM PDT

As you say, for those of us who grew up on Windows...

A few months ago I was cooperating on a presentation with a few people and we were huddled around one computer writing the slides. It was actually an evil (Windows) computer, so the picture is complete. Whenever I'd write what I was thinking and stop a minute to think, I hit Ctrl+S instinctively. Someone noticed this and pointed it out, I wasn't even aware that I was doing it, I always do this.

Quoth dum8d0g on April 18, 2009 @ 6:19 PM PDT

I grew up on MS-DOS Win95 Win98 Win98SE so I have this habbit too. I do it automaticaly, but when I do typo mistake in ':w' command, I notice that I'm saving the file and I laugh myself in mind ( and in meantime I save the file ). It's interesting that people who grew up on WinXP or so don't have this habbit (so strong). By the way, did you noticed, how fast you can type the ':w' command? ;-)

Quoth Adam on January 23, 2012 @ 1:08 AM PST

This was a great idea, but when using vim in the terminal, this clears the screen every time I hit :w. I don't understand the syntax quite well enough to know where to put a ":redraw!" command - could you add that? Otherwise, wonderful tip.