|

Vim as KMail’s External Editor

Vim is my favourite text editor and I also prefer to use Vim to compose Email. I ever used Vim as Thunderbird’s External editor with the help of plugin. I started to use KMail as my email client on KDE and I find it is not hard to configure KMail to use Vim as email editor with a little help from Konsole and shell.

KMail has a nice feature that can use external editor to compose email. In “Settings->Configure Kmail->Composor->General”, there is a option to “Use external editor instead of composer”, and we can specify the editor we like to use. The %f will be replaced with the file name of the email to edit which is copied to a temporary location.

It is possible to use KWrite as the editor and configure KWrite to use “Vi input mode”, but that is not convenient enough for geeks like me—I prefer the Vim in a shell/terminal!

Now, let’s see how I use Vim in the shell as KMail’s external editor.

A small script as the wrapper to call Vim

Vim is a command line tool and we can not directly run it. Instead, we should run Vim in a shell. In KDE, let’s just use Konsole. The external editor is actually a instance of Konsole with Vim as its command. Below is the script I wrote to invoke Konsole and Vim. Let’s call it kcallvim:

#!/bin/bash

email=$1.eml
cp $1 $email

# --nofork is needed, otherwise the content is not updated
# no other konsole instance running
konsole --nofork --geometry 1000x600 -e vim $email

cp $email $1 && rm -f $email

One tricky thing here is the “–nofork” option when invoking konsole. This option make the konsole command not return until Vim exits.

Put this script to a directory in the $PATH, or use the full path when invoking this script in Kmail.

Configure KMail to use kcallvim as the external editor

In KMail’s configuration tool, select the option of “Use external editor instead of composer”, and, in the “external editor” field, fill

kcallvim %f

as shown in the figure.

That’s it. When composing or editing email, hit Enter or any key, the Vim will start in a Konsole. Then you can edit the email in Vim as editing any other text files. After you save the email and exit Vim, the Konsole will close automatically and the email will appear in KMail.

Similar Posts

  • Configure sMobileNet of HKUST on Linux

    How to configure NetworkManager to connect to sMobileNet in HKUST is introduced in this post. The wireless network connection configuration for sMobileNet in NetworkManager The SSID is “sMobileNet” Wireless security is “WPA & WPA2 Enterprise” Authentication is “Protected EAP (PEAP)” Anonymous identity is “” (empty) CA certificate is “(None)” (there will be a warning appear,…

  • How to detect memory leaks of C programs in Linux?

    How to detect memory leaks of C programs in Linux? I also have access to the source code of the program. There are many posts related to this: Easy and quick tools on Linux (while not very accurate): http://blog.thewebsitepeople.org/2011/03/linux-memory-leak-detection/ Valgrind: manual and a tutorial. gperftools has the Google Heap Profiler which can checks for memory…

  • Configuring Mouse Cursor Style for GTK Applications in KDE Desktop

    Update on Jan. 7, 2012: The package for the gtk application style setting on KDE 4.7 is kcm-gtk. The command to install this package is: “# yum install kcm-gtk”. One annoying thing when using KDE desktop is that the theme and style of GTK applications differ from KDE’s. The gtk-qt-engine can let us select the…

  • Chinese Charactor Configuration on Fedora 11

    最新的更新版本请看: Fedora 中文字体设置. 使用Linux时我个人倾向使用英文环境系统,而Fedora11在英文环境下中文字体有时会不太好看,经常遇到需要字体优化美化的问题。 以下是我的配置方案,经测试效果还算不错,解决了Fedora 11 中文字体难看的问题: 方案1:使用uming和ukai字体,即AR PL UMing CN等。 关键是使用的字体包如下: 首先要安装这两个字体: cjkuni-ukai-fonts cjkuni-uming-fonts 然后配置一下~/.fonts.conf文件. 使sans-serif serif monospace字体中文使用uming/ukai即可. 我的.fonts.conf文件可以从这里下载(两种选择, 我喜欢前者): https://github.com/zma/config_files 使用Liberation和uming/ukai字体: .fonts.cofn.liberation 使用dejavu和uming/ukai字体: .fonts.conf.dejavu 下载后放到自己的$HOME下改名为.fonts.conf就可以了。 使用uming字体效果如下(请放大后看效果): 方案2:安装文泉驿字体,这个非常简单,安装相应包即可了。 如果喜欢其它的字体选择性的安装上就可以了,只要注意只安装自己需要的就行了。有人使用微软雅黑字体,首先这是侵权的,其次开源的字体做得其实已经很不错了。 最后将字体平滑选项打开, KDE和gnome都有相关设置方法。 以上内容只是针对使用xft字体系统的设置。对于使用核心字体系统的X程序来说字体依然会出现很丑的情况。 下面是针对emacs的设置方法: 首先需要安装这个字体包: xorg-x11-fonts-misc 注意到在中文系统下emacs的中文显示非常好,而在英文环境中去非常差,我们可以利用这一点,在运行emacs前首先将系统环境设为中文即可。 在~/bin/下建立一文件ema 内容如下: #!/bin/bash rm -f ~/.emacs ln -s ~/.emacs.x ~/.emacs LANG=zh_CN.UTF-8 emacs –fullheight -r $* 然后加入执行权限即可: chmod +x…

Leave a Reply

Your email address will not be published. Required fields are marked *