-1

below is my vimrc code:

   " widen or narrow a window
    nmap <M-l> 10<c-w>>
    nmap <M-h> 10<c-w><
    " increase of decrease the hight of a window
    nmap <M-j> 8<c-w>-
    nmap <M-k> 8<c-w>+

I'm using kitty on window and ssh into an Ubuntu server. When I start neovim, the mapping is working correctly, but when I start normal vim, it just doesn't work at all, nothing happens. Below is the result when I run vim --version:

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug  3 2016 23:52:02)
Included patches: 1-2152
Compiled by i056958@mo-cebd4b858
Huge version with GTK2 GUI.  Features included (+) or not (-):
+acl             +file_in_path    +mouse_sgr       +tag_old_static
+arabic          +find_in_path    -mouse_sysmouse  -tag_any_white
+autocmd         +float           +mouse_urxvt     -tcl
+balloon_eval    +folding         +mouse_xterm     +termguicolors
+browse          -footer          +multi_byte      +terminfo
++builtin_terms  +fork()          +multi_lang      +termresponse
+byte_offset     +gettext         -mzscheme        +textobjects
+channel         -hangul_input    -netbeans_intg   +timers
+cindent         +iconv           +num64           +title
+clientserver    +insert_expand   +packages        +toolbar
+clipboard       +job             +path_extra      +user_commands
+cmdline_compl   +jumplist        -perl            +vertsplit
+cmdline_hist    +keymap          +persistent_undo +virtualedit
+cmdline_info    +lambda          +postscript      +visual
+comments        +langmap         +printer         +visualextra
+conceal         +libcall         +profile         +viminfo
+cryptv          +linebreak       +python          +vreplace
+cscope          +lispindent      -python3         +wildignore
+cursorbind      +listcmds        +quickfix        +wildmenu
+cursorshape     +localmap        +reltime         +windows
+dialog_con_gui  +lua             +rightleft       +writebackup
+diff            +menu            +ruby            +X11
+digraphs        +mksession       +scrollbind      -xfontset
+dnd             +modify_fname    +signs           +xim
-ebcdic          +mouse           +smartindent     +xsmp_interact
+emacs_tags      +mouseshape      +startuptime     +xterm_clipboard
+eval            +mouse_dec       +statusline      -xterm_save
+ex_extra        +mouse_gpm       -sun_workshop    +xpm
+extra_search    -mouse_jsbterm   +syntax
+farsi           +mouse_netterm   +tag_binary
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/gio
-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/libpng12 -I/usr/in
clude/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_
64-linux-gnu/glib-2.0/include -I/usr/include/freetype2   -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic  -L/usr/local/lib -Wl,--as-needed -o vim
 -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -l
freetype -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl  -L/usr/lib -llua5.2  -L/usr/lib/python3/dist-p
ackages -lpython2.7   -lruby-2.3 -lpthread -lgmp -ldl -lcrypt -lm
  • 3
    One of the changes introduced by Neovim is a better input handling. Alt mappings simply don't work in CLI Vim. Look around SO for various discussions on Alt mappings in Vim. – romainl Aug 4 '16 at 5:36
5

Historically, Alt and certain Ctrl keys cannot be reliably detected across all systems Vim runs on. Basically it depends on the terminal configuration how certain keys are passed on to Vim.

Also, since keyboard handling internally uses the ASCII charset, it is not possible to distinguish e.g. between Ctrl-H and BS key, since by definition the backspace key is the same as Ctrl-H. (The same holds true for Ctrl-I and Tab.) Therefore you often get the annoying behaviour when mapping the ctrl key, that the same mapping triggers when pressing another key.

Also, historically, pressing Alt was not an own key, but basically just toggled the high bit of the second character. e.g. the terminal would see ALT-a as á, which means when you map ALT-a the same mapping would trigger when you press á. However this also depends how your terminal was configured e.g. it is possible that pressing ALT would send an escape sequence followed by the actual key. (This is btw. one of the reasons, why sometimes Vim waits a little after receiving an escape key to see, if there is another key coming). Also cursor keys usually send an <escape>[<letter> sequence which is the reason, why those keys usually don't work in compatible mode).

To make this easier, Vim includes several options to handle certain aspects of the input handling better, e.g. esckeys option or the various timeout settings or many of the terminal related t_xx keycodes and some of them are even triggered with the compatible/nocompatible setting.

This means however, that configuring Vim is really complex, since there are so many options and many depends on how your $TERM variable is set and how your terminal is setup.

On the graphical version, things look a lot better, and therefore it often works with Gvim, but on the console you are bound to whatever the terminal detects.

Putting it all together, this means, mapping and (in combination with <shift>) is not reliably detected by Vim (or the terminal). And therefore, it is not recommended to use those keys for mapping.

Now the neovim guys have changed the input handling and rely on an extra library that is supposed to detect keys better in the terminal. This library was not available back in the days, when Vim was developed, therefore Vim does not use it (yet). I am not sure, if keyboard handling in the terminal is so much better in Neovim, at least I see a lot of keyboard related questions in the neovim bug tracker.

See also the faq here and here

  • I think Neovim works better with some "common" setups, where "common" means "what the Neovim devs" use, but actually makes matters worse for "uncommon" setups (which is fair enough, they're doing the legwork after all). – Martin Tournoij Aug 4 '16 at 11:11
  • @Carpetsmoker Possibly, I don't really know, since I don't use Neovim. I am an old school Vimer and have grewn too much accustomed to the pecularities of the Vim input handling. – Christian Brabandt Aug 4 '16 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.