How can I see which keys vim thinks I'm pressing?

Is there a way to get an xev-like mode where I can press keys and key combinations and vim will print out which keys or characters it thinks I'm pressing?

A specific problem with this: I have key bindings that work on MacVim and GVim, but they don't work on the vim terminal, which I use on Linux on top of SSH inside the screen. I came to the conclusion that the reason is that vim thinks that the keys I press are different from the way MacVim interprets them.

In my .vimrc:

map <M-,> :split<CR> " Horizontal split map <M-.> :vsplit<CR> " Vertical split map <M-/> :close<CR> 

In my vim :map (MacVim shows the same thing):

 ¯ :close<CR><Space> ® :vsplit<CR> " Vertical split ¬ :split<CR> " Horizontal split 

It works on MacVim and GVim, but does not work on any terminal based terminal. I tried this on several terminals (OSX and Term2 terminals, KDE terminal, Gnome terminal, etc.). I also saw this with other modifiers and key combos. It seems that vim captures keystrokes, but interprets them as something other than <M-,> , for example.

I would like to know that vim thinks that I click, so I can write mappings accordingly.

+6
source share
1 answer
  • i to switch to insert mode.
  • <Cv> .
  • <key> or combo.
  • Vim prints the raw keypress / combo value.

Here (the Gnome terminal on Ubuntu 11.04), typing i<Cv> , then <Alt> , and then prints something similar to ^[, , which means "Escape". The Alt key (which I think you want to use for <Meta> ) is not recognized as <Meta> and not as <Alt> .

The immediate conclusion is that the CLI Vim does not like <M-> (and many terminal emulators do not handle it very well). Some terminal emulators allow you to map the <Alt> key to Meta , but this is not an ideal cross-platform solution (I use <Alt> lot in Mac OS X to enter special characters).

On this machine

 nnoremap ^[, :split<CR> " ^[ is <Cv><Esc> 

does exactly what I think you want.

If you absolutely want to continue using <M-> shortcuts in both the GUI and the CLI, you will need to support two separate sets of shortcuts. If you have dozens of user mappings in your .vimrc , this will quickly become a little difficult to manage.

This is why I think you should use mappings that work everywhere, like:

 :nnoremap <leader>, :split<CR> :nnoremap <leader>. :vsplit<CR> :nnoremap <leader>/ :close<CR> 

The <leader> key is the default <leader> , but I set it to <leader>

Please note that you do not need to use the <leader>key , just displaying ,, ,. and ,/ .

See :help <leader> .

+6
source

Source: https://habr.com/ru/post/914469/


All Articles