|

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

  • How to view a file at a specific commit in git?

    How to view a file at a specific commit/revision in git? You can use git show to view a file’s content at a specific commit in git: https://www.systutorials.com/docs/linux/man/1-git-show/ $ git show REVISION:/path/to/file You can also save a copy by $ git show REVISION:/path/to/file >file.copy Read more: How to produce a patch file for a specific…

  • Floating Point in Bash Shell

    Integers are natively supported in Bash shell. However, what if we use floating point in Bash shell? The short and direct answer is using ‘bc‘ command – “An arbitrary precision calculator language.” Just run bc  and enter some floating point calculation expression, such as “1.2+8.2”, bc will give the result. In a script, we certainly…

  • How to get an environment variable in Python?

    In Python, how to get an environment variable? In Python, you may use this piece of code to get an environment variable: os.environ.get(‘ENV_MIGHT_EXIST’) or this piece of code: os.getenv(‘ENV_MIGHT_EXIST’) It will return None if the environment variable is not present. Reference and for more ways, please check https://www.systutorials.com/dtivl/13/how-to-get-an-environment-variable?show=80#answer-80 . Read more: How to get an…

  • How to force a checkpointing of metadata in HDFS?

    HDFS SecondaraNameNode log shows 2017-08-06 10:54:14,488 ERROR org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode: Exception in doCheckpoint java.io.IOException: Inconsistent checkpoint fields. LV = -63 namespaceID = 1920275013 cTime = 0 ; clusterId = CID-f38880ba-3415-4277-8abf-b5c2848b7a63 ; blockpoolId = BP-578888813-10.6.1.2-1497278556180. Expecting respectively: -63; 263120692; 0; CID-d22222fd-e28a-4b2d-bd2a-f60e1f0ad1b1; BP-622207878-10.6.1.2-1497242227638. at org.apache.hadoop.hdfs.server.namenode.CheckpointSignature.validateStorageInfo(CheckpointSignature.java:134) at org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode.doCheckpoint(SecondaryNameNode.java:531) at org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode.doWork(SecondaryNameNode.java:395) at org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode$1.run(SecondaryNameNode.java:361) at org.apache.hadoop.security.SecurityUtil.doAsLoginUserOrFatal(SecurityUtil.java:415) at org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode.run(SecondaryNameNode.java:357) It seems the checkpoint…

Leave a Reply

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