Search code examples
vimkey-bindingsgnome-terminalautokey

Why is this key remapping not working in Vim?


This problem is getting me really crazy. I used Gvim and Autohotkey under Windows 7 in the past. For various reasons, I mapped CTRL+D to behave likes Enter. This worked well so far. In Gvim I mapped the Enter/Return to act as page down key:

nnoremap <cr> <PageDown> 

This worked good. Previous week I decided to give Ubuntu a try again.

With Autokey, I remapped my CTRL+D to behave likes Enter.

keyboard.send_key("<enter>")

This worked fine in everything in Ubuntu/Xubuntu, in browser/Chrome, in text editors, everything. I'm using Gnome Terminal. And there, CTRL+D behaves like Enter.

When I am in Vim in insert mode, CTRL+D does the same as Enter. In normal mode, I don't get the expected behaviour with nnoremap .

I found this very odd, given the fact the CTRL+D worked good in terminal and in insert mode in Vim. When I press the 'real' Enter. I get the behaviour (Page down in Vim) but I don't get the same behaviour with mapped CTRL+D in normal mode. In insert mode, it behaves like Enter. I tried to change the maps, in order to detect the problem, like:

nnoremap <return> <PageDown>

nnoremap <Enter> <PageDown>

nnoremap <cr> ij

nnoremap <CR> ij

Nothing of them worked so far with CTRL+D in normal mode. I find it oddly that it worked well in Insert mode and in terminal. I looked into Vim's manual to get some ideas what went here. With no results sofar.

I use Vim as my daily editor, so I feel so angry about this, because I don't understand why this issue occur in normal mode. Anyone know what is going on there? I would really appreciate your help, because this is making me really crazy.


Solution

  • I didn't get fixed. So I decided to hack it in a another way.

    This is my Autokey script

    winTitle = window.get_active_title()
    if 'VIM' in winTitle:
        output = "<f8>"
        keyboard.send_key(output)
    
    else:
        output = "<PageDown>"
        keyboard.send_key(output)
    

    You see, if I have the VIM window, CTRL+D will send F8 to Vim.

    I mapped in Vim the F8 like this:

    map <f8> <CR>
    nnoremap <CR> <PageDown>
    

    It worked, but not in the way it was meant to be. But I had no another choice, it seems. Thank you Zyx and romainl for your help, much appreciated!