20

I hope this does not come across as an attempt to spark conversation purely for the sake of doing so.

I use vim a great deal (5-10 hours a day) and I noticed my left wrist is the first to start aching. The standard keyboard layout (see image below) is almost guaranteed to give you arthritis.

Standard Keyboard

Currently, I have remapped

  • Ctrl to Shift
  • Shift to Caps Lock
  • Caps Lock to Ctrl

This helps with common commands such as Ctrlf or Shift2 (@), but I still have to twist my wrist to get at those combinations. Is there anyway to remap the keys so as to avoid this twisting on the left wrist (maybe use the Tab key)? I just find it odd that for a text editor designed specifically for programmers, it would make heavy use of these out of the way keys. I have considered remapping to the old keyboard layout (see below image), but I don't want to learn that if it is going to have the same fundamental problems as my current remapping.

old keyboard layout

puk
  • 16,318
  • 29
  • 119
  • 199
  • 5
    Consider using USB footswitches for things like ! I just got a two-pedal switch unit this week and I'm already thrilled with it. – asfallows Jul 12 '12 at 18:45
  • @asfallows I didn't think of that, but I had tried mapping random buttons on keyboards (ie zoom), but it had mixed results – puk Jul 12 '12 at 20:48

9 Answers9

15

Note: I am not a doctor, just another typist that suffered from wrist pain.


In my experience, just mapping Caps to Ctrl (or swapping the two if you must have a Caps) and using Ctrl+[ instead of Esc make a big difference. Ctrl+[ does not require an additional mapping in vim as it is equivalent to Esc. If you can teach yourself this small change you reduce your movement by a great deal when you consider how often you use Esc in vim.

The Caps to Ctrl mapping can't be done inside vim and will have to be made system-wide, however, having Ctrl in the more convenient location will also help in other applications that use Ctrl combinations. There are different methods of remapping keys depending on which OS you're using. A few common options are:

While this will probably improve your situation you really should consider seeing a doctor and/or purchasing a more ergonomically designed keyboard if your pain persists. I own an older version of the Kinesis Advantage that I picked up used on Ebay for about $100 (USD) and I couldn't be happier. The keys can be programmed directly on the keyboard so no software is needed to swap keys or create your own keyboard macros for frequently used key strokes.


Edit: I see in your post you also mention combinations like Ctrl+f and Shift+2 requiring you to twist your wrist to press. It sounds to me like you're only using the Ctrl and Shift keys on the left side of your keyboard. You should really be using both sets of these keys, using whichever one is on the opposite hand of the key you're modifying. That would negate this wrist movement.

Randy Morris
  • 39,631
  • 8
  • 69
  • 76
6

Use caps as ctrl systemwide. (How often do you cut/copy/paste?)

This also makes ctrl[ work in vim.

Alongside I use the vim 'arpeggio' plugin.

Arpeggio lets you define vim bindings that are activated when two keys are simultanously pressed.
jk pressed serves me as ESC.

Also the 'surround.vim' plugin might be interesting for you.

Eliminated all my wrist pains.

post scriptum:
Use 'vundle'!
Its the best vim plugin manager by far, and you will wonder how you could ever do without, especially if you use a customized vim on several machines. Don't be scared if you have trouble setting it up initially, take your time.

sjas
  • 18,644
  • 14
  • 87
  • 92
4

I switched to a Kinesis Advantage keyboard, and remapped Caps Lock to Esc. This effectively removed any wrist pain I felt as a vim user.Once again not a doctor, but looking at how my hands move, I don't see my wrist twisting even when I hit Shift.

You could probably do some great remappings to the thumb keys to further minimise tension, but to be honest I've never felt the need.

Not a $0 solution, I'm afraid, but it was very effective for me.

Yaniv
  • 991
  • 6
  • 13
4

I mapped both Escape (single tap) and Ctrl (hold) to CapsLock:

xmodmap -e "remove Lock = Caps_Lock"
xmodmap -e "remove Control = Control_L"
xmodmap -e "keysym Control_L = Caps_Lock"
xmodmap -e "keysym Caps_Lock = Control_L"
xmodmap -e "add Control = Control_L"
xcape -t 1000 -e "Control_L=Escape" # Fire nothing if 1000ms hold time out

Probably I'm messing things up here, but xmodmap isn't the best option to modify mappings anyway, so I will change that to pure xkb config.

I have also swapped : with ; and ` with ~, since I use : and ~ more often:

xmodmap -e "keycode 47 = colon semicolon"
xmodmap -e "keycode 49 = asciitilde grave"

I also use Compose Key to be able to type ūmlauts et c.

In vim, the most useful change I have ever made is mapping of space to leader. All kinds of leader-key combinations will make your life easier.

I couldn't get used to H and L for _ and $, since it doesn't seem to work with surround.vim and some other tricks people advise.

Just don't use arrows!

phil pirozhkov
  • 4,740
  • 2
  • 33
  • 40
2

I'd make this part a comment to Randy's answer on Esc if I could, but it demands a little more space. There's one important use case where you can't just remap Windows keys: Windows 7 without admin rights. It's common enough in an enterprise environment; at the very least, it describes me and that keyboard in the pic. keymapper's repo has decent info on this issue:

Important note for Windows 7 Users

Windows 7 does not support per-user key mappings. Until the next release of Key Mapper, you will have to manually switch to 'Boot' mappings from the Mappings menu, reboot to change the mappings, and you will need to have Administrative access to your computer to set key mappings that will work in Windows 7.

The same is true for any Microsoft tools, KeyTweak, SharpKey, etc.

So you'll have to use something like AutoHotkey. I personally prefer mapping Caps Lock directly to Esc for Vim, and I've had issues just mapping it to Ctrl:

#IfWinActive ahk_class Vim
*CapsLock::Esc
#IfWinActive

Another alternative I like is inoremap jj <Esc>. Unless you plan to write about a hajj or something it works pretty well.


More to your point

In any case, have you considered doing the above for easy escaping and then remapping some of the hard-to-reach insert mode commands to Alt (hit it with your thumb) and then using mappings to your leader?

let mapleader=","
nnoremap <leader>f <C-F>
brymck
  • 7,555
  • 28
  • 31
  • I use `jj` for escape, but I do admit, it only works in insert mode. – puk Jul 12 '12 at 05:37
  • @puk Yeah, I saw your comment just after editing, so I guess new information. The limitation with the leader key, of course, is that it only helps outside insert mode, but have you considered mapping more things that way? – brymck Jul 12 '12 at 05:42
  • it was my understanding that you can't map the alt key in vim (only gVim). But I believe that's besides the point. Ultimitely many of the shift and ctrl keys 'criss cross', for example shift w vs shift C or ctrl x vs ctrl a. It requires a jerking motion. The leader options also has the drawback that u have to release and press the leader key every time – puk Jul 12 '12 at 05:50
  • I will try out this kinesis advantage keyboard as in a way my problem is with the way vim developed in response to keyboards. I like how most of the keys you use are on the home row (h,j,k,l, or a,i,o or p,yy) but I don't like how they used out of the way buttons like shift or ctrl. That darn space bar key is using up way too much real estate!!! – puk Jul 12 '12 at 05:53
  • Just tried to install Autohotkey in an unprivileged account, but it required an Administrator password :/ – jplindstrom Oct 15 '13 at 14:24
1

I would suggest remapping

  • Caps lock to left Control
  • Left Control to Escape
  • Escape to Caps lock

. If in linux first can be done by using setxkbmap -option '...,ctrl:nocaps' or changing XkbOptions in /etc/X11/xorg.conf. Second requires using of xmodmap. After some X server update I failed to get the third working, previously used xmodmap as well.

Using dvorak layout (maybe even programming) that is optimized for touch typing and mappings like ,s->()<Left> might also help.

Note: I am not a doctor as well. I am touch typist, but unlike @Randy Morris I never suffered from the wrist pain, just moved keys to the most convenient locations.

ZyX
  • 52,536
  • 7
  • 114
  • 135
  • `setxkbmap -option caps:escape` Works for me to use caps as esc (caps:swapescape to swap). Check out my answer for an even better remap. – phil pirozhkov May 01 '14 at 00:38
1

I always press the left ctrl key by curling up my pinky and pressing with the first knuckle. I find this requires less hand movement.

Update

I don't find Shift uncomfortable, so I can't help you with that. However Ctrl does bother me, and even with my knuckle technique I prefer to avoid it where possible. So for insert mode (and command-line mode) I use a leading ; instead of Ctrl. E.g.

:map! ;w <C-W>
:map! ;a <C-A>
:map! ;r <C-R>
:ino  ;t <C-T>
:ino  ;d <C-D>

You get the idea.

In normal mode I use v and V instead of Ctrl+F and Ctrl+B (I only use visual blockwise mode), though I imagine most people would prefer to map different keys, such as <Space> and - for paging (- isn't really needed). Instead of F you could search forwards with f, and then hit ,.

I've never really seen much point in Ctrl+D or Ctrl+U. However I do find z., z<Enter>, and z- useful for scrolling the line with the cursor to the middle, top, and bottom of the window respectively. H, M and L are also useful for moving the cursor around the screen. But in general I prefer to just use / with 'incsearch' set for navigating about.

There's no right or wrong way to do this, these are just my personal preferences, but I hope it gives you one or two ideas. Try experimenting and see what works for you.

1983
  • 5,882
  • 2
  • 27
  • 39
  • Move your palm to the left slightly as well. Of course you can't reach as far with your other fingers then, but it helps. Also I'll do e.g. Ctrl+F with both hands. And something else I meant to ask: how come you are using Ctrl and Alt so much in Vim anyway? – 1983 Jul 12 '12 at 20:18
  • two hands helps sometimes. Ctrl A/X I use for increment/decrement. Ctrl D/F/U/B obviously. Ctrl W for backspace (insert mode). Shift V for hilighting lines, Shift C to change to end of line, Shift S to change entire line, Shift A to append to end of line, Shift F/T for backwards find/till. There are others I don't even yet use, like Shift B/E/W. – puk Jul 12 '12 at 21:00
  • Ah, I see. I've edited my answer with some more details about my setup. – 1983 Jul 13 '12 at 02:06
1

I've developed a vim module to do some simple remappings for exactly this issue:

https://github.com/vim-scripts/vim.ergonomic

The biggest things it does is make it easier to type bracket sets. It also makes it much easier to get into command mode (jj->ESC)

It runs on the principle that you hardly ever used the J key while editing, but it is right there in the home row... so let's abuse it!

from the documentation:

Remapping commonly used commands
  key combo     mapping         purpose
  ;             :               removes the need to hit Shift to use commands
  jj            <ESC>           can exit edit mode quickly and easily
  Jj            j               can type 'j' when you need to
  JJ            J               can type 'J' when you need to


Making it easier to insert various kinds of braces:
  key combo     mapping         purpose
  JU            ()<left>        easier to create parenthesis
  JI            []<left>        easier to create square brackets
  JM            {}<left>        eaiser to create curly braces
  J<            <><left>        easier to create carrot braces


Make it easier to move small distances (especially useful with braces commands):
  key combo     mapping         purpose
  JL            <left>          move left in insert mode
  JH            <right>         move right in insert mode


Removing any need for enter, backspace or delete:
  key combo     mapping         purpose
  JB            <esc>ldbi       delete the previous word
  JW            <esc>dwi        delete the next word
  JO            <esc>oi         insert line and go to it
Luca Invernizzi
  • 6,489
  • 3
  • 28
  • 26
vitiral
  • 8,446
  • 8
  • 29
  • 43
  • 1
    The link doesn't work anymore, now it is on: https://github.com/vim-scripts/vim.ergonomic – agold Feb 21 '16 at 11:57
0

A lightweight and easily reversible suggestion is to swap the caps lock and the escape key using these aliases in your .bashrc file:

# swap caps and escape
alias se='setxkbmap -option caps:swapescape'
# clear keyboard map settings - restore caps and escape
alias ce='setxkbmap -option'

This enables you to test out if you like using the keyswaps and undo them if you don't.

You can apply them in vim by e.g.

<esc>
:!se
Oppy
  • 2,662
  • 16
  • 22