1

Often find I introduce errors when trying to yank, but accidentally press u instead of y.

I tried the below, but it doesn't help as that's targeting undo.

Is there a special way to remap keys when you have text selected?

    nnoremap u <Nop>
dreftymac
  • 31,404
  • 26
  • 119
  • 182
zipprrr
  • 99
  • 8
  • No, it's mostly an issue when I (very) occasionally hit u in visual mode when something selected. I guess because I don't notice until later (compile time, etc) it is becomes an issue, while under other circumstances its immediately obvious. – zipprrr Jun 30 '18 at 03:08
  • 6
    You could try `vnoremap u ` – builder-7000 Jun 30 '18 at 05:40
  • Thanks Sergio that's the solution! didn't know about vnoremap. – zipprrr Jun 30 '18 at 10:31
  • 1
    No idea why someone would mark this down, as it's a real question with a real answer. SO is a bit snobby. – zipprrr Jun 30 '18 at 10:32
  • Not exactly a programming question, in my opinion. It's just "how do I use vim?". – melpomene Jun 30 '18 at 11:02
  • your problem is, try pressing `y` instead of `u` to yank! you have to learn it. – Kent Jun 30 '18 at 13:34
  • 1
    No it's not. My problem was I wanted to reassign a key. I explained why, but if you have a problem with that I'm afraid it's actually none of your business. I can change my editor to do what I want. – zipprrr Jul 01 '18 at 05:48

1 Answers1

1

The right answer is

xnoremap u <Nop>

Although it is a useful action for visual mode and has it's uses so I would instead recommend you to fix your bad habits instead of remapping this key.

Also, there's a slight difference between vnoremap and xnoremap in that when using the v variant (whether to map or unmap) it also does so for the special vim SELECT mode other than VISUAL mode, which has special use case, used specifically by templating libraries such as ultisnips, snipmate etc. In most cases you want to use x variants to apply your mappings for this reason to restrict them to apply only for VISUAL mode and not also for SELECT mode.

Dhruva Sagar
  • 7,089
  • 1
  • 25
  • 34
  • It's not a bad habbit. The y and u key are right next to each other. Everyone occasionally hits the wrong key. The difference here is that in visual mode hitting the wrong key causes a change this is often suble or not even noticable (you might not be wrapping the text, for example, and the change could happen off screen). So no. It's not a bad habbit. If I inserted a u instead of a y I would notice immediately and fix the human error. It's not a bad habbit. If anything it's an slight drawback with vim workflow that I am trying to get around by making it less likely to happen. – zipprrr Jul 04 '18 at 01:11
  • While I understand your point of view, I still believe it's a case of being counter productive where you're removing a valuable functionality (visual mode `u`) to work around a human error. – Dhruva Sagar Jul 04 '18 at 05:59