2

I'm trying to add a simple mapping to visually select recently pasted text. However, even though `[v`] is working correctly in a vim session, when I try to use it in my .vimrc file, it doesn't work. Other mappings work correctly, though.

This is the mapping as described here:

nnoremap  gV `[v`]

What could be causing this issue? I tried to disable the plugins but the issue still occurs.

By the way, the keyboard I'm using was configured to include a dead tilde. I just changed it to type backtick ` instead of `<space>.

I also tried to change the encoding using set encoding=utf-8 but didn't help.

UPDATE:

Since I can't escape backticks in the comments, I will be answering here.

@Nobe4 I'm just adding nnoremap gV `[v`] at the end of my .vimrc file and then after pasting some text, I press gV. As I said, other mappings are working but this one doesn't do anything noticeable. I also tried to use gp as a replacement, but then vim listens to the p command and simply pastes again the same text.

@Christian Brabandt The thing that doesn't work is the mapping from gV to `[v`]. If I type `[v`] in some file, it does visually select the pasted text as intended.

UPDATE 2:

@Nobe4 helped me to figure this out. The issue was that vim wasn't responding to mappings containing two (or more) characters. The issue was caused by the timeoutlen option. I'm using set timeoutlen=50 to remove a delay after pressing escape in order to change to normal mode. In the meanwhile, I change it to timeoutlen=300 but this has a noticeable delay in the status bar. Any suggestions are welcomed.

UPDATE 3:

Okay. I'm using set timeoutlen=1000 ttimeoutlen=10 and now the delay is fixed and mappings are working correctly. Hopefully, this won't have unintended effects down the road.

  • Have you tried with launching vim without your config ? vim -u NONE -N, Maybe it's your configuration that cause the issue ... Also, you can read vi.stackexchange.com/a/2004/1821 – nobe4 Aug 21 '15 at 6:57
  • Sure, I tried that. Unfortunately, it doesn't work. By the way, I think the problem is that the mapping doesn't work but the commands work if I type them manually. – Robert Smith Aug 21 '15 at 7:27
  • I got it working on my vimrc file ... Can you give more informations about how you are doing this and how to reproduce your problem ? – nobe4 Aug 21 '15 at 8:23
  • 1
    What exactly "doesn't work"? Please be precise with your problem description. – Christian Brabandt Aug 21 '15 at 11:49
  • 1
    I'll do it, I though it was necessary... Thanks for inviting me to do – nobe4 Aug 22 '15 at 15:04
2

After some discussion with Robert Smith, here is the conclusion:

The problem was not the mapping nor the command per se. The problem was the timeout that the vim configuration was using.

The timeout is configured by the options:

timeoutlen   : mapping delay
ttimeoutlen  : key code delay 

For example, in MacVim 7.4 the default configuration is:

timeoutlen=1000
ttimeoutlen=-1

It means that for both mappings and key codes, the time of 1000 ms is applied. Vim will wait 1 second before the mapping/key code completes.

The set of values that solves the problem are:

timeoutlen=1000 
ttimeoutlen=10

It means that a mapping will wait 1 second to complete (as before) whereas a keycode will complete after only 10ms.

When checking for a non-firing mapping, it should be good advice to see those values.

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.