cohama / lexima.vim

Auto close parentheses and repeat by dot dot dot...
1.01k stars 46 forks source link

Mapping <Esc> breaks special chars / use InsertLeave? #10

Closed blueyed closed 9 years ago

blueyed commented 9 years ago

Because of the <Esc> mapping, special keys that use escape codes in the terminal are broken, e.g. cursor keys.

While it can be disabled, it's meant to serve a purpose, I guess?!

if !g:lexima_no_map_to_escape
  inoremap <silent> <Esc> <C-r>=lexima#insmode#escape()<CR><Esc>
endif

Would using InsertLeave be an alternative here?

cohama commented 9 years ago

No. That function must be called before InsertLeave.

Do you want to use arrow keys in InsertMode? I will fix broken arrow keys problem in near future.

blueyed commented 9 years ago

That function must be called before InsertLeave.

Yes, I've noticed that.

I've tried a bit using feedkeys in InsertLeave, but without success.

Do you want to use arrow keys in InsertMode?

The issue is not just about cursor keys, but any Escape/Alt-keys. Another example is that I have mapped <A-[hjkl]> in insert mode - Alt/meta also uses an escape sequence.

cohama commented 9 years ago

Can you tell me details. I tried

inoremap <A-a> foo
inoremap <M-a> foo
inoremap <Esc>a foo

but nothing happened.

blueyed commented 9 years ago

inoremap <A-a> foo works for me, but not in vim -u NONE -N.

I use the following to set them up:

fun! MySetupAltMapping(c)
  " XXX: causes problems in macros: <Esc>a gets mapped to á.
  "      Solution: use <C-c> / jk in macros.
  exec "set <A-".a:c.">=\e".a:c
  " XXX: Necessary?!
  " exec "imap \e".a:c." <A-".a:c.">"
  " insert and command line mode:
  " exec "map! \e".a:c." <A-".a:c.">"
endfun
for [c, n] in items({'a':'z', 'A':'N', 'P':'Z', '0':'9'})
  while 1
    call MySetupAltMapping(c)
    if c >= n
      break
    endif
    let c = nr2char(1+char2nr(c))
  endw
endfor
" for c in [',', '.', '-', 'ö', 'ä', '#', 'ü', '+', '<']
for c in [',', '.', '-', '#', '+', '<']
  call MySetupAltMapping(c)
endfor

I've came across a (possibly relevant) setting: esckeys. Maybe this can be used to tweak/fix the process somehow.