如何让VIM在写信时播放打字机声音?

发布于 2024-10-07 07:49:27 字数 252 浏览 7 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

吃颗糖壮壮胆 2024-10-14 07:49:27

好吧,这有点疯狂,但它似乎有效。首先,为自己获取 aiff 格式的打字机声音。然后将打字机声音放入 ~/.vim/support/my_typewriter_sound.aiff 中。然后将以下内容添加到您的 ~/.vimrc 中。

function! PlaySound()
  silent! exec '!afplay ~/.vim/support/my_typewriter_sound.aiff &'
endfunction
autocmd CursorMovedI * call PlaySound()

请注意,上面的函数调用了 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.

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.

吝吻 2024-10-14 07:49:27

该插件确实存在。您可以在这里找到它: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

始终不够 2024-10-14 07:49:27

如果您使用的是 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

裂开嘴轻声笑有多痛 2024-10-14 07:49:27

你应该尝试 Qweritckle

它是一个 Linux 打字机声音模拟器。

You should try Qweritckle

It's a typewriter sound emulator for Linux.

一袭白衣梦中忆 2024-10-14 07:49:27

有趣的想法,感谢 Trotter 的回答。然而,根据你的回答,我发现在我的系统(Ubuntu 14.04)中,Vim 在每次按键时都会变成空白,并显示以下消息:

按 ENTER 或键入命令继续

基于关于在 Vim 中静默执行命令主题的讨论,网址为 https://vi.stackexchange.com/questions/1942/how-to-execute-shell-commands-silently 我尝试过:

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

自动清除空白屏幕,但每次按键后我都可以看到闪烁而且这些声音是在最后一次按键完成后才产生的,造成了一种非常不自然和癫痫的体验。在同一问题中,OliverUv 给出了重要的解释:Vim 同步执行,这意味着它会等待执行完成后再继续。他建议使用 vim-dispatch 或 Neomake 进行异步执行,但最终我选择了 Do for Vim 因为它更适合执行任意 shell 命令而不是特定的编译任务。 Do for Vim 利用 Vim 中内置的 Python 支持在单独的线程上运行每个命令(异步)。我对使用该插件的结果非常满意,如下所示:

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

屏幕没有闪烁,各个按键声音重叠,产生真正的咔嗒咔嗒的级联点击。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文