如何让VIM在写信时播放打字机声音?
在Windows 上的 Q10 上写了很多东西之后,我已经习惯了每次你打字时发出的打字机声音按一个键。至少对我来说,拥有这种声音反馈感觉很棒。
另一方面,在 Linux 上,我喜欢用 VIM 编写它,因为它的编辑功能。我怎样才能将这个功能添加到 VIM 中?
简单地说,我想在插入模式下每次按下按键时播放声音。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
好吧,这有点疯狂,但它似乎有效。首先,为自己获取 aiff 格式的打字机声音。然后将打字机声音放入
~/.vim/support/my_typewriter_sound.aiff
中。然后将以下内容添加到您的~/.vimrc
中。请注意,上面的函数调用了
afplay
,我知道它可以在 Mac 上运行,并且需要在 Linux 上替换为play
。在 Windows 上,我不知道。所以你知道上面发生了什么,我们首先创建一个名为
PlaySound
的函数,它向afplay
进行 shell 处理。然后,我们设置一个自动命令,只要光标在插入模式下移动,该命令就会被触发。当它触发时,它会调用PlaySound
。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
.Note that the above function calls out to
afplay
, which I know works on a Mac and needs to be replaced withplay
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 toafplay
. We then setup an autocommand that gets fired anytime the cursor moves in insert mode. When it fires, it callsPlaySound
.该插件确实存在。您可以在这里找到它:https://github.com/osyo-manga/vim-sound
但是,您需要自己添加音效文件,您可以在这里找到:
http://www.soundjay.com/typewriter-sounds.html
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
如果您使用的是 Solaris,则可以使用这组脚本 DTrace 内核键盘驱动程序: http://www.brendangregg.com/DTrace/typewriter-0.75.tar.gz
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
你应该尝试 Qweritckle
它是一个 Linux 打字机声音模拟器。
You should try Qweritckle
It's a typewriter sound emulator for Linux.
有趣的想法,感谢 Trotter 的回答。然而,根据你的回答,我发现在我的系统(Ubuntu 14.04)中,Vim 在每次按键时都会变成空白,并显示以下消息:
基于关于在 Vim 中静默执行命令主题的讨论,网址为 https://vi.stackexchange.com/questions/1942/how-to-execute-shell-commands-silently 我尝试过:
自动清除空白屏幕,但每次按键后我都可以看到闪烁而且这些声音是在最后一次按键完成后才产生的,造成了一种非常不自然和癫痫的体验。在同一问题中,OliverUv 给出了重要的解释:Vim 同步执行,这意味着它会等待执行完成后再继续。他建议使用 vim-dispatch 或 Neomake 进行异步执行,但最终我选择了 Do for Vim 因为它更适合执行任意 shell 命令而不是特定的编译任务。 Do for Vim 利用 Vim 中内置的 Python 支持在单独的线程上运行每个命令(异步)。我对使用该插件的结果非常满意,如下所示:
屏幕没有闪烁,各个按键声音重叠,产生真正的咔嗒咔嗒的级联点击。
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:
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:
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:
There is no flickering of the screen and the individual keypress sounds overlap for an authentic clattering cascade of clicking.