Frage

Nach viel schreiben in Q10 auf Windows , habe ich mich an die Schreibmaschine Sound verwendet es macht jedes Mal, drücken Sie eine Taste. Zumindest für mich fühlt es sich großartig, diese Art von Sound-Feedback zu haben.

Unter Linux auf der anderen Seite, ich liebe es zu schreiben es VIM, weil es Funktionen bearbeiten. Wie könnte ich diese Funktionalität VIM hinzufügen?

Einfach gesagt, Ich mag jedes Mal, wenn ich in dem Insert-Modus eine Taste drücken, um einen Ton spielen.

War es hilfreich?

Lösung

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.

Andere Tipps

The plugin does exist. You can find it here: https://github.com/osyo-manga/vim-sound

However, you need to add sound effects files yourself, which you can find here: http://www.soundjay.com/typewriter-sounds.html

If you're on Solaris, you can DTrace the kernel keyboard driver with this set of scripts: http://www.brendangregg.com/DTrace/typewriter-0.75.tar.gz

You should try Qweritckle

It's a typewriter sound emulator for Linux.

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top