2

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.

Julius Martin
  • 159
  • 2
  • 8
  • What _is_ received by Vim in normal mode? Press `:`, what gets displayed? If it's the default `^M` (or anything else mappable), you could just workaround with `:nnoremap `. – Ingo Karkat May 24 '14 at 16:29
  • Thanks for your reply. I typed in the command line of Vim the following : Then I receive an error: E488: Trailing characters. But there are no spaces in my command. Why am I get that message? – Julius Martin May 24 '14 at 17:28
  • @JuliusMartin Try using `while nr2char(getchar(1)) != "\" | echomsg string(getchar(1)) string(nr2char(getchar())) | endwhile`: it should echo received characters in a form `code 'character'`. Though as you was on windows I would also check `:` because you probably have `behave mswin` somewhere and that remaps ``. – ZyX May 24 '14 at 17:34
  • @JuliusMartin Or, alternatively, you misunderstood what @IngoKarkat was saying. You *must not* type `:` *literally*. You must replace `` with CTRL-v and `` with your `` that is remapped to ``. – ZyX May 24 '14 at 17:36
  • By the way, trailing characters are trailing *characters*, not trailing *spaces*. If you typed it literally then Vim will interpret your text as a `:<` command (short version of `:left` which shifts indent) followed by garbage characters (`:<` only accepts numbers as its argument, not `C-v>`). – ZyX May 24 '14 at 17:41
  • You can also try mapping `` and ``: these are different keys, but they produce the same behavior as `` where I tested. `` is also worth testing, it should be an alias to `` though. – ZyX May 24 '14 at 17:49
  • ZyX, you're right. Your help is really appreciated. I was interpreting it literally. After I pressed the :, I receive the message ^M (I assume the ^ means control) which stands for Enter/Return. I tried the remappings and , although I don't understand why you think could stands for Enter. Surprisling, both of them are not working with CTRL+D. After that, I tried <^M>. Vim luckily accepts that map, but CTRL+D doesn't give the Enter behaviour. – Julius Martin May 24 '14 at 17:54
  • `nnoremap ` and `nnoremap ` should what you want. – romainl May 24 '14 at 17:58
  • I got it fixed in very another way. I will explain it in my answer, for a better layout. – Julius Martin May 24 '14 at 18:52

1 Answers1

1

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!

Julius Martin
  • 159
  • 2
  • 8