DervishD wrote:
    Hi all :)

    I'm having a problem that I know how to solve, but I wonder if I'm
doing the right thing...

    Some weeks ago I asked a couple of things about encodings on the
list, and based on the answers, I finally did a proper setup to edit
UTF-8 files from time to time in my latin1 terminal, while at the same
time treating new ASCII files as latin1 and not utf-8. This works OK.

    But now my problem is the following. I've chosen "ç" as my
mapleader. This is due its position in my keyboard. BUT, its code in
latin1 is 0xe7 and, in utf8 it's 0xc3+0xa7.

    This means (and this is my problem) that if I set "setlocal
enc=utf8", I'm no longer able to use it as my mapleader as-is. I still
generate "ç" when I press it, of course, and vim translates it onto
something my terminal understands as "ç". I assumed that it was doing
the same for mappings, but it is not.

    Am I doing anything wrong? Should I set another thing so even with
"enc=utf8" my high-bit-set-mapleader still works? Should I set
"mapleader" to the utf8 value?

    Thanks a lot in advance :)

    Raúl Núñez de Arenas Coronado


Regarding your Subject: 'encoding' is a global option; it defines how the characters are represented internally in memory for _all_ buffers.

When you store a mapping, it is stored in the 'encoding' current at the moment the mapping is defined. If that 'encoding' is Latin1, the letter ç (small c-cedilla) is stored as the single byte 0xE7.

After ":set encoding=utf-8", the byte 0xE7 is invalid unless it is immediately followed by two bytes in the range 0x80-0xBF. The small c-cedilla is still the codepoint U+00E7 but that codepoint is now represented in memory as the two bytes 0xC3 0xA7.

Therefore, you should set 'encoding' early in your vimrc, as follows:

set nocompatible
if has("unix")
  language messages C
else
  language messages en
endif
runtime vimrc_example.vim
if has("multi_byte")
  if &enc !~? '^u'
    if &tenc == ""
      let &tenc = &enc
    endif
    set enc=utf-8
  endif
  set fencs=ucs-bom,utf-8,latin1
  setglobal bomb fenc=latin1
else
  echomsg "Multi-byte support not compiled-in"
endif
...
let mapleader = "\<Char-0xE7>"
...
map <Leader>abc   call myFunctionABC()
...


Best regards,
Tony.
--
In specifications, Murphy's Law supersedes Ohm's.

Reply via email to