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

前端 未结 5 1032
天涯浪人
天涯浪人 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 04:57

    Fun idea, and thanks for the answer Trotter. However, using your answer I found with my system (Ubuntu 14.04) that Vim went blank at each keypress with the message:

    Press ENTER or type command to continue

    Based on discussion on the topic of executing commands silently in Vim at https://vi.stackexchange.com/questions/1942/how-to-execute-shell-commands-silently I tried:

    function! PlaySound()
      silent! exec '!play ~/.vim/support/my_typewriter_sound.wav &' | :redraw!
    endfunction
    autocmd CursorMovedI * call PlaySound()
    

    which cleared the blank screen automatically, but I could see the flicker after each keypress and the sounds were only produced after the last keypress was finished, making for quite an unnatural and epileptic experience. In the same question OliverUv gave the important explanation that Vim executes synchronously, meaning it waits to continue until the execution is completed. He suggests vim-dispatch or Neomake for asynchronous execution, but in the end I went with Do for Vim as it is more geared towards executing arbitrary shell commands rather than specific compilation tasks. Do for Vim utilizes built-in Python support in Vim to run each command on a separate thread (asyncronously). I am very pleased with the results using this plugin as follows:

    function! PlaySound()
      :DoQuietly play ~/.vim/support/my_typewriter_sound.wav
    endfunction
    autocmd CursorMovedI * call PlaySound()
    

    There is no flickering of the screen and the individual keypress sounds overlap for an authentic clattering cascade of clicking.

提交回复
热议问题