My text editor of choice is "vi", or more specifically "vim" (VI Improved). For further information, see the vim home page at: http://www.vim.org/ If you're hazy on the distinction between a text editor and, say, a word processor, then you'd probably better avoid this chapter entirely.
As usual, nothing about the discussion here is complete. These are just random notes for my own use. Write it down so I won't forget it; post it in public so I always know where I put what I wrote down.
As I write this, I'm using vim 6.3 as distributed with SuSE Linux 10.0. Things noted here might or might not work on earlier versions or on versions compiled differently. All of the multibyte stuff seems to be enable. I use the ordinary "in-terminal" vi, not the GUI-enabled gvim.
CNTL-V u XXXX
Terminate the entry of digits either by typing all four or by typing a non-hex character. If you do this latter, it'll be interpreted as itself (so if you type a space and don't want it, you'll have to backspace over it; if you type an Esc you'll leave Insert mode).
Four hex digits are enough for everything in the Basic Multilingual Plane (BMP), but the Supplemental Multilingual Plane (SMP; where for example the Cypriot Syllabary is) and the rest of Unicode require more digits. To enter arbitrary Unicode in vim as up to eight hex digits:
CNTL-V U XXXXXXXX
It is also possible to enter multibyte characters using "digraphs" (pairs of characters mapped to multibyte sequences). I don't do this, so I'll just note here how the documentation says it is to be done. To see what digraphs are defined:
Note: "g8" will show the literal multibyte hex value, which in UTF-8 encoding won't be the same as the UCS-2 or UCS-4 Unicode value. You don't want to (or I don't want to) do UTF-8 decoding in your (my) head.
:set encoding=utf-8 :map <F2> :set keymap=greek_utf-8<CR> :map <F3> :set keymap=<CR> :imap <F2> <Esc><F2>a :imap <F3> <Esc><F3>a
The ":map" sets up a keyboard mapping; F2 and higher function keys have no default values in vim, and so are handy to use for this. The command mapped is the setting of the keymap. The "<F2>", "<CR>", etc. are typed literally (that is, type less-than-sign, F, 2, greater-than-sign; don't simply press the F2 key). The :map applies to Normal, Visual, and Operator Pending modes. The :imap applies to Insert mode. In Insert mode, the command escapes to Normal mode, executes the previously defined F2 command (to do the keymapping), and then with the "a" gets back into insert mode at the right place.
To do the same with a user-written keymap, first put it in the system keymap directory (I'll assume I have root, as I do this on a home system). Then, e.g. for my Cypriot Syllabary keymap (/usr/share/vim/current/keymap/cypriot-syllabary_utf-8.vim):
:map <F6> :set keymap=cypriot-syllabary_utf-8<CR> :map <F7> :set keymap=<CR>
:imap <F4> <i> :imap <F5> </i> :map <F4> i<F4><Esc> :map <F5> i<F5><Esc>
:help map-overview :help unicode :help usr_45.txt 45.3 encodings; using Unicode in the GUI 45.5 entering language text (keymaps) :echo globpath(&rtp, "keymap/*.vim") :help usr_40.txt about making new commands :help i_CTRL-V_digit about hexadecimal character entry
I find that with the encoding set up correctly it is not necessary to mess with details such as the Unicode "Byte Order Marker" in my UTF-8 files. Should it be necessary to insert the Unicode Byte Order Marker in a UTF-8 file, though, use CTRL-V u FEFF. Here's an example of the results of doing this with a new (empty) file:
$ hexdump testfile 0000000 bbef 0abf
All portions of this document not noted otherwise are Copyright © 2006-2007 by David M. MacMillan and Rollande Krandall.
Circuitous Root is a Registered Trademark of David M. MacMillan and Rollande Krandall.
This work is licensed under the Creative Commons "Attribution - ShareAlike" license. See http://creativecommons.org/licenses/by-sa/3.0/ for its terms.
Linux is a registered trademark of Linus Torvalds.
SuSE is a registered trademark of Novell Corporation.
Unicode is a registered trademark of The Unicode Consortium.
Presented originally by Circuitous Root®
Select Resolution: 0 [other resolutions temporarily disabled due to lack of disk space]