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.

r_31415
  • 576
  • 4
  • 13
  • 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 http://vi.stackexchange.com/a/2004/1821 – nobe4 Aug 21 '15 at 06: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. – r_31415 Aug 21 '15 at 07: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 08:23
  • 1
    What exactly "doesn't work"? Please be precise with your problem description. – Christian Brabandt Aug 21 '15 at 11:49
  • For some reason, the double backtick to escape symbols doesn't work here. I will update the question. – r_31415 Aug 21 '15 at 14:36
  • I did exactly the same and still I don't reproduce the issue :/ – nobe4 Aug 21 '15 at 14:41
  • @Nobe4 I know! This shouldn't be so hard, but I guess something related to the backtick is causing this issue. – r_31415 Aug 21 '15 at 14:45
  • You check this question : http://vi.stackexchange.com/questions/3134/override-a-mapping-with-leader-key The part with the :help key-mapping may help you... Also, have you tried with ' instead of backticks ? – nobe4 Aug 21 '15 at 14:48
  • Thank you. I read that section, but I don't think it helps a lot. The issue with ' is that the command to visually select pasted text doesn't work if I use ' instead of `. Should it work with both? – r_31415 Aug 21 '15 at 15:00
  • Yes it should, see :h '], you tried with only one mapping ? – nobe4 Aug 21 '15 at 15:07
  • @RobertSmith: As you found a solution to your problem could you make an answer to explain what you did instead of putting it in the question please? (You'll find a button "Answer Your Question" at the bottom of this page) – statox Aug 22 '15 at 11:08
  • I know but I was expecting @Nobe4 to post an answer to mark it as correct. – r_31415 Aug 22 '15 at 15:03
  • 1
    I'll do it, I though it was necessary... Thanks for inviting me to do – nobe4 Aug 22 '15 at 15:04
  • Does the same issue happen when using the solution in http://stackoverflow.com/questions/28417300/in-vim-how-to-visual-select-previously-pasted-text ? – Vitor Aug 26 '15 at 12:55
  • @Vitor Yes, it was happening also with that solution, but this was due to the timeoutlen option which didn't let me to use mappings with more than one letter. – r_31415 Aug 26 '15 at 21:23

1 Answers1

4

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.

nobe4
  • 16,033
  • 4
  • 48
  • 81