写信时如何使VIM播放打字机声音? [英] How can I make VIM play typewriter sound when I write a letter?
问题描述
在Windows上的 Q10 上写了很多书之后,我习惯了打字机发出的声音每次您按下一个键.至少对我来说,拥有这种声音反馈感觉很棒.
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.
另一方面,在Linux上,我喜欢编写VIM,因为它具有编辑功能.我如何才能将此功能添加到VIM?
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?
简单地说,我想在插入模式下每次按一个键都播放声音.
推荐答案
好的,这有点疯狂,但它似乎可以工作.首先,抓住aiff格式的打字机声音.然后将打字机声音放入~/.vim/support/my_typewriter_sound.aiff
中.然后将以下内容添加到您的~/.vimrc
.
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()
请注意,上面的函数调用了afplay
,据我所知,该功能在Mac上可以运行,在Linux上需要替换为play
.在Windows上,我不知道.
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.
所以您知道上面发生了什么,我们首先创建一个称为PlaySound
的函数,将其封装到afplay
中.然后,我们设置了一个自动命令,只要光标在插入模式下移动,该命令就会被触发.触发时,它会调用PlaySound
.
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
.
这篇关于写信时如何使VIM播放打字机声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!