La documentación de vim sobre modo Multi-byte support relativa a unicode dice:
Useful commands:
ga
shows the decimal, hexadecimal and octal value of the character under
the cursor. If there are composing characters these are shown too. (If the
message is truncated, use ":messages").
g8
shows the bytes used in a UTF-8 character, also the composing
characters, as hex numbers.
:set encoding=utf-8 fileencodings=
forces using UTF-8 for all files. The
default is to use the current locale for 'encoding' and set 'fileencodings'
to automatically detect the encoding of a file.
....
If your current locale is in an utf-8 encoding, Vim will automatically start in utf-8 mode.
If you are using another locale:
set encoding=utf-8
En nuestro caso, tenemos las locale usando utf-8:
casiano@millo:~/Lperltesting$ locale LANG=es_ES.UTF-8 LC_CTYPE="es_ES.UTF-8" LC_NUMERIC="es_ES.UTF-8" LC_TIME="es_ES.UTF-8" LC_COLLATE="es_ES.UTF-8" LC_MONETARY="es_ES.UTF-8" LC_MESSAGES="es_ES.UTF-8" LC_PAPER="es_ES.UTF-8" LC_NAME="es_ES.UTF-8" LC_ADDRESS="es_ES.UTF-8" LC_TELEPHONE="es_ES.UTF-8" LC_MEASUREMENT="es_ES.UTF-8" LC_IDENTIFICATION="es_ES.UTF-8" LC_ALL=
Hay varias formas de crear ficheros Unicode en lenguajes fuera del rango del latin1 con vim.
Los caracteres unicode en la línea 3 del siguiente fichero
han sido generados en vim
insertandolos
mediante su codificación usando la secuencia CTRL-V u hexcode
.
lhp@nereida:~/Lperl/src/testing$ cat -n utf8file.txt 1 áéíóúñÑ 2 àèìòùÇç 3 ェッニは大きEn concreto los códigos creo que fueron:
30a7
, 30c3
, 30cb
, 306f
, 5927
y 304d
.
pl@nereida:~/Lperltesting$ perl5.10.1 -C7 -E 'say chr($_) for (0x30a7, 0x30c3, 0x30cb, 0x306f, 0x5927, 0x304d)' ェ ッ ニ は 大 きUna forma mas cómoda de insertar caracteres Unicode en vim es usar keymaps :
:echo globpath(&rtp, "keymap/*.vim")Para entender el comando anterior hay que tener en cuenta que:
globpath({path}, {expr} [, {flag}])
y realiza un glob de {expr}
sobre la lista de directorios
en {path}
.
{expr1} ..
muestra los valores
de {expr1}
, .. separados por espacios.
Esto mostrará algo como:
/usr/share/vim/vim70/keymap/accents.vim /usr/share/vim/vim70/keymap/arabic.vim /usr/share/vim/vim70/keymap/arabic_utf-8.vim /usr/share/vim/vim70/keymap/bulgarian.vim /usr/share/vim/vim70/keymap/canfr-win.vim /usr/share/vim/vim70/keymap/czech.vim /usr/share/vim/vim70/keymap/czech_utf-8.vim /usr/share/vim/vim70/keymap/esperanto.vim /usr/share/vim/vim70/keymap/esperanto_utf-8.vim /usr/share/vim/vim70/keymap/greek.vim /usr/share/vim/vim70/keymap/greek_cp1253.vim /usr/share/vim/vim70/keymap/greek_cp737.vim /usr/share/vim/vim70/keymap/greek_iso-8859-7.vim /usr/share/vim/vim70/keymap/greek_utf-8.vim ....Como se ve el convenio de nombres para los keymaps es:
<language>_<encoding>.vimSigue un ejemplo de fichero de keymap:
$ cat -n /usr/share/vim/vim70/keymap/greek_utf-8.vim 1 " Vim Keymap file for greek 2 " Maintainer: Panagiotis Louridas <louridas@acm.org> 3 " Last Updated: Thu Mar 23 23:45:02 EET 2006 4 ....................................................................... 72 let b:keymap_name = "grk" 73 loadkeymap 74 " PUNCTUATION MARKS - SYMBOLS (GREEK SPECIFIC) 75 " 76 E$ <char-0x20AC> " EURO SIGN ............................................................................ 115 " 116 " GREEK LETTERS 117 " 118 A <char-0x0391> " GREEK CAPITAL LETTER ALPHA 119 B <char-0x0392> " GREEK CAPITAL LETTER BETA 120 G <char-0x0393> " GREEK CAPITAL LETTER GAMMA 121 D <char-0x0394> " GREEK CAPITAL LETTER DELTA 122 E <char-0x0395> " GREEK CAPITAL LETTER EPSILON 123 Z <char-0x0396> " GREEK CAPITAL LETTER ZETA
:set keymap=greekCuando estamos en modo inserción podemos conmutar entre los dos keymaps tecleando
CTRL-^.o bien
CTRL-6.
vim
:
:set encoding encoding=utf-8Es posible cambiar la codificación con la que se está editando:
:set encoding latin1Esto no modifica la codificación del fichero.
:help
mbyte.txt
:help
mbyte-keymap
Casiano Rodríguez León