Jakub Arnold Jakub Arnold - 2 years ago 122
Linux Question

How can I make VIM play typewriter sound when I write a letter?

After a lot of writing in Q10 on Windows, I got used to the typewriter sound it makes every time you press a key. At least for me it feels great to have this sort of sound feedback.

On Linux on the other hand, I love writing it VIM, because of it's editing features. How could I add this functionality to VIM?

Simply said, I want to play a sound every time I press a key in the insert mode.

Answer Source

Alright, this kinda crazy, but it appears to work. First, grab yourself a typewriter sound in aiff format. Then put that typewriter sound in ~/.vim/support/my_typewriter_sound.aiff. Then add the following to your ~/.vimrc.

function! PlaySound()
  silent! exec '!afplay ~/.vim/support/my_typewriter_sound.aiff &'
endfunction
autocmd CursorMovedI * call PlaySound()

Note that the above function calls out to afplay, which I know works on a Mac and needs to be replaced with play on Linux. On Windows, I have no idea.

So you know what's happening above, we're first creating a function called PlaySound that shells out to afplay. We then setup an autocommand that gets fired anytime the cursor moves in insert mode. When it fires, it calls PlaySound.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download