7

I have a bad habit of using the shift key of the same side of the keyboard as the letter when tying uppercase letters. To type a D, for example, I press the left shift with my left pinky and d with my left index finger. It is better to use the right shift in combination with keys on the left hand side of the keyboard, and vise versa.

To get rid of this habit I would like to disable the combinations of either shift key with keys on the same side of the keyboard. I can map shift-d with <S-d>, but this applies to both shift keys. Is there a to apply only to the right hand shift key?

  • 3
    I don't think this is possible in Vim to differentiate a A (S-a either with right or left shift). Maybe try looking for your terminal or keyboard configuration. – nobe4 Mar 2 '16 at 10:30
  • Just a note - why is this a bad habit? Type however works for you, and is most comfortable. – fruglemonkey Mar 2 '16 at 22:56
  • @frugle It is a bad habit because it is uncomfortable and often makes me stretch my fingers in awkward positions that interrupt my typing. For me, the beauty of vim is how it allows for speed and flow, and this habit breaks that. – Andreas Mar 3 '16 at 0:02
  • Fair point. But as note RE: speed and flow, wont you break your flow if you habitually type <LShift>+d, which wont output anything, and then have to remember to use your <Rshift>+d mapping, instead? And there are times when using <LShift>+d could be warranted (One handed typing, or if your right hand is on a numpad, etc.), which this mapping will prevent you from doing, presenting further potential disruptions down the line. It seems that this mapping causes a circular problem (Problem A causes symptom B, Fix problem A with solution C that also causes symptom B). Better to fix the root problem – fruglemonkey Mar 3 '16 at 1:44
  • 1
    The idea is to implement the mapping only to unlearn the bad habit and then remove the mapping. I've done this before with some success. I have a mapping <jj> to delete the last word while in insert mode to avoid having to repeatedly smash backspace. To get the hapit of using it I also had to map thee successive presses on backspace to do nothing. When I had learnt not to flail at backspace I removed this second mapping. – Andreas Mar 3 '16 at 8:36
9

From the Vim FAQ 20.4. "I am not able to create a mapping for the key. What is wrong?":

1) First make sure, the key is passed correctly to Vim. To determine if this is the case, put Vim in Insert mode and then hit Ctrl-V (or Ctrl-Q if your Ctrl-V is remapped to the paste operation (e.g. on Windows if you are using the mswin.vim script file) followed by your key.

If nothing appears in the buffer (and assuming that you have 'showcmd' on, ^V remains displayed near the bottom right of the Vim screen), then Vim doesn't get your key correctly and there is nothing to be done, other than selecting a different key for your mapping or using GVim, which should recognise the key correctly.

On my setup issuing Ctrl-q+Left Shfit-d displays 'D', and issuing Ctrl-q+Right Shfit-d leads to the same result. So at least here Vim is unable to detect the difference.

But maybe you could use some other tool to aid you on this; for instance, on Windows you could try AutoHotkey with something like this:

#ifWinActive ahk_class Vim
LShift & d::MsgBox You pressed the wrong 'Shift'!
#ifWinActive

or to simple ignore the combination:

#ifWinActive ahk_class Vim
LShift & d::
#ifWinActive
  • Any suggestion for Mac? I'll wait a while and se of there are other answers. If not I will accept this. – Andreas Mar 2 '16 at 15:32
  • @Andreas this site lists AHK alternatives for Mac – mMontu Mar 2 '16 at 16:23
  • I highly recommend Seil (the karabiner's successor) :) – nobe4 Mar 2 '16 at 18:58
  • For OSX there is now Karabiner-Elements with ready-made settings to disable left-shift with right-hand letters etc. pqrs.org/osx/karabiner/complex_modifications/#key_specific – Andreas Nov 11 '17 at 8:19

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.