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

前端 未结 5 1043
天涯浪人
天涯浪人 2021-01-30 04:30

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 feedb

5条回答
  •  死守一世寂寞
    2021-01-30 05:11

    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.

提交回复
热议问题