Preface: This has nothing to do with Vim as such, but I will show you what I consider to be the "best" way to insert these characters by far; Vim's digraph system is more or less the same, but it only works with Vim. This will work in all applications.
This will only work for X11 systems (Linux, BSD, etc.). For Windows, there's AllChars. It hasn't been updated in a while, but I can confirm it works well with Windows 7 (used it at my previous job). I believe OS X also has good facilities to do this built in the OS; if you use OS X, I encourage you to check them out, but as I've never really used OS X I can't point you to them.
The below is (part of) a draft weblog article I have in the pipeline. Unfortunately a truly comprehensive guide doesn't exist (yet), and the below doesn't describe all the features it offers (for example, some parts about dead keys are missing) and could be better written in some parts, but I think it's still "useful enough".
A ‘compose sequence’ is pressing the Compose key and then one or more characters to produce some character not found on your keyboard, for example, pressing Compose, immediately followed by " and a might produce an ä
.
By default, Compose isn’t bound to any key1; the Right Alt key (aka. Alt Gr) is often used, but you set this to any key you want.
Set it using xmodmap
You can use xmodmap
to set this:
$ xmodmap -e 'keysym Alt_R = Multi_key' # Set it right Alt
$ xmodmap -e 'keysym Caps_Lock = Multi_key' # Set it to Caps Lock
$ xmodmap -e 'keysym F12 = Multi_key' # You're free to use *any* key, like F12
You probably want to add this to your ~/.Xmodmap
file2:
! Set compose key
keysym Alt_R = Multi_key
Set it using XKB
You can also set the compose key as an option to XKB with
setxkbmap
:
setxkbmap -option compose:ralt # Right alt
setxkbmap -option compose:caps # Caps Lock
To make these permanent, add the command to your X startup file, or
alternatively, you can also set it in /etc/X11/xorg.conf
:
Section "InputDevice"
Identifier "Keyboard0"
Driver "kbd"
Option "XkbOptions" "compose:ralt"
#Option "XkbOptions" "compose:caps"
EndSection
Or, in a more ‘modern’ style, you can create a file
/etc/X11/xorg.conf.d/90-compose.conf
:
Section "InputClass"
Identifier "Set compose key"
MatchIsKeyboard "on"
Option "XkbOptions" "compose:ralt"
EndSection
A list of possible values can be found in xkeyboard-config(7)
, section ‘Position of Compose key’3.
Setting up dead keys
A dead key is chiefly used to add a accent or diacritic to a letter (such as the umlaut, accent grave, etc.), although it can be used to create any character. It works by...TODO
'
keycode 133 = dead_greek NoSymbol SuperR
http://zuttobenkyou.wordpress.com/2011/08/24/xorg-using-the-us-international-altgr-intl-variant-keyboard-layout/
http://stackoverflow.com/questions/14922007/how-to-enter-greek-alpha-under-xor
keycode 48 = dead_grave apostrophe
<dead_grave> <space> : "`" grave # GRAVE ACCENT
<dead_grave> <dead_grave> : "`" grave # GRAVE ACCENT
<dead_grave> <a> : "À" agrave # LATIN CAPITAL LETTER A WITH GRAVE
Making a ~/.XCompose file
The default Compose file if ~/.XCompose
is missing is
/usr/share/X11/locale/$LANG/Compose
. Having your own ~/.XCompose
overrides the default, but you can still include the default with:
include "%L"
Changes to any Compose file takes effect when you restart an application. You don't need to restart X.
Compose key
A 'compose sequence' is pressing the Compose key and then one or more characters to produce some character, for example:
<Multi_key> <quotedbl> <a> : "ä" adiaeresis
Means that pressing Compose, immediately followed by " and
a produces an ä
.
<Multi_key>
denotes that we're using the Compose key.
we then follow this by a list of one or more keys, these have to be keysyms
, which are symbolic representations of keys used by X (See the Keysyms section).
Followed by a :
, followed by the result.
The result:
<Multi_key> <a> : "ä" adiaeresis
<Multi_key> <b> <b> : "ä" adiaeresis
<Multi_key> <c> <c> <c> : "ä" adiaeresis
<Multi_key> Alt <d> : "ä" adiaeresis
<Multi_key> Ctrl <e> : "ä" adiaeresis
Note: A Compose file is case-sensitive, so A
is not the same as a
.
Dead keys
TODO
Make it work in GTK & Qt
Set the environment variables GTK_IM_MODULE
& QT_IM_MODULE
to xim
.
Bourne shell:
# Make compose key work for GTK, Qt
export GTK_IM_MODULE=xim
export QT_IM_MODULE=xim
C shell:
# Make compose key work for GTK, Qt
setenv GTK_IM_MODULE xim
setenv QT_IM_MODULE xim
See Also
My ~/.XCompose
This is the ~/.XCompose
that I use;
I used a script to generate this, but I accidentally overwrote this when compiling it >_< So I need to rewrite it.
Also take note of this line:
<Multi_key> <i> <b> : "NL65AEGO0721647952"
Pressing Compose ib will insert this string (a random test IBAN number); very useful for testing applications where such a number is required to create some object (Person, Organisation); XCompose can also serve as a "snippet" tool :-)
Footnotes
1:
Some UNIX keyboards had a dedicated Compose key (like this
SUN),
but this is fairly uncommon these days.
2:
Depending on your existing setup, this may or may not be read at startup,
depending on your config, add the line xmodmap ~/.Xmodmap
to either
~/.xinitrc
or ~/.xsession
;
also see the ArchLinux wiki.
3:
Reproduced for your benefit:
Position of Compose key
+------------------------------------------------------+
|Option Description |
+------------------------------------------------------+
|compose:ralt Right Alt |
|compose:lwin Left Win |
|compose:lwin-altgr 3rd level of Left Win |
|compose:rwin Right Win |
|compose:rwin-altgr 3rd level of Right Win |
|compose:menu Menu |
|compose:menu-altgr 3rd level of Menu |
|compose:lctrl Left Ctrl |
|compose:lctrl-altgr 3rd level of Left Ctrl |
|compose:rctrl Right Ctrl |
|compose:rctrl-altgr 3rd level of Right Ctrl |
|compose:caps Caps Lock |
|compose:caps-altgr 3rd level of Caps Lock |
|compose:102 <Less/Greater> |
|compose:102-altgr 3rd level of <Less/Greater> |
|compose:paus Pause |
|compose:prsc PrtSc |
|compose:sclk Scroll Lock |
+------------------------------------------------------+