Tuesday, April 18, 2017

Console Vim: Still can't get keys with leading key-codes to work in Insert mode

I use a lot of key mappings with Meta keys, when using console vim, I have the following codes in my .vimrc file:

let char= 'a'
while char <= 'z'
exec "set <M-" . char . ">=\<Esc>" . char
let char= nr2char(1+char2nr(char))
endwhile
exec "set <M-" . '.' . ">=\<Esc>" . '.'

set notimeout
set ttimeout
set ttimeoutlen=100

After these settings, all the key mappings with Meta keys work seamlessly in both Normal and Command mode, but not in Insert mode, Vim acts like always interpreting those key codes as one <Escape> key followed by another key in Insert mode. Cursor keys (←↑→↓) don't work either.



I found out that I actually can make the Insert mode key mappings work, only if I explicitly set at least one mapping with the leading <Escape> key:

inoremap <Esc>m <nop>

but this isn't a solution as it will introduce ambiguity to the Escape key. Setting 'timeout' and 'timeoutlen' options in turn ain't solution either as they will void all the other key mappings with multiple key strokes.


Is there any way to work around this problem? Thanks.

I use Ubuntu 16.04 with Gnome Terminal, typing ":set term?" in my vim shows "term=xterm-256color", and below is the output of the :version command:



:version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Apr 3 2017 22:40:41)
Included patches: 1-540
Compiled by jacky
Huge version with GTK2 GUI. Features included (+) or not (-):
+acl +clipboard +dialog_con_gui +file_in_path +job -lua +mouse_sgr +path_extra +rightleft +tag_old_static +user_commands +writebackup
+arabic +cmdline_compl +diff +find_in_path +jumplist +menu -mouse_sysmouse -perl -ruby -tag_any_white +vertsplit +X11
+autocmd +cmdline_hist +digraphs +float +keymap +mksession +mouse_urxvt +persistent_undo +scrollbind -tcl +virtualedit -xfontset
+balloon_eval +cmdline_info +dnd +folding +lambda +modify_fname +mouse_xterm +postscript +signs +termguicolors +visual +xim
+browse +comments -ebcdic -footer +langmap +mouse +multi_byte +printer +smartindent +terminfo +visualextra -xpm
++builtin_terms +conceal +emacs_tags +fork() +libcall +mouseshape +multi_lang +profile +startuptime +termresponse +viminfo +xsmp_interact
+byte_offset +cryptv +eval +gettext +linebreak +mouse_dec -mzscheme -python +statusline +textobjects +vreplace +xterm_clipboard
+channel +cscope +ex_extra -hangul_input +lispindent -mouse_gpm +netbeans_intg +python3 -sun_workshop +timers +wildignore -xterm_save
+cindent +cursorbind +extra_search +iconv +listcmds -mouse_jsbterm +num64 +quickfix +syntax +title +wildmenu
+clientserver +cursorshape +farsi +insert_expand +localmap +mouse_netterm +packages +reltime +tag_binary +toolbar +windows


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: