Vim Tips Wiki
Advertisement
Tip 327 Printable Monobook Previous Next

created September 13, 2002 · complexity basic · author Nithin · version 6.0


I use my left thumb for the alt key and right for the space. Using this combo, you can get some useful key maps for which you don't have to move your hands. I find I have to turn my hand a little to press the left ctrl key.

These are some maps I use for C programming.

map ' `
map <C-f> :w<C-m>:!make<C-m>
map <M-]> <C-]>                     Tags
map <M-[> <C-t>                     Tags
map <M-u> :!ctags -R *<C-m>         Build Tags
map <M-c> I/*<Esc>A*/<Esc>            Comment current line
map <M-d> ^xx$xx                  Delete comment for a single line
map <M-l> [{zf%                   Fold upto the enclosing brace level
map <M-o> zo                              Open fold
map <M-i> zc                              Close fold
map <M-.> :cn<C-m>                  Go to next error in list
map <M-,> :cp<C-m>                  Previous error in list

imap <Tab> <C-p>                    Complete word
inoremap <S-Tab> <Tab>                      Tab
inoremap { <CR>{<CR>                        Brace and line
inoremap } <CR>}                  brace and line. saves one enter stroke

imap <M-j> <Esc>                    Escape. Don't want to move my hand to esc key.
imap <M-k> <C-y>                    Copy line from above.
imap <M-q> /*  */<Esc>hhi           Comment selected lines

noremap <M-r> ddko{<C-m>}<Esc>kpko    Convert a simple statement to a compound statement. And place cursor above prev line.
noremap <M-k> ddko{<C-m>}<Esc>kpo     Same as above but place cursor below old line.

vnoremap <M-j> <Esc>
vnoremap <M-c> di/*<C-m>/<C-m><Esc>kkp  Commented selected text

nmap <M-n> :noh<CR>                 No hilight

RSI Warning

I was baffled to read that you are attempting to reduce your hand movements to the minimum [with these key mappings] while you are typing. Surely you know that this makes you a very good candidate for RSI (Repetitive Strain Injury). Experts recommend that the hands "float" over the keyboard, with the fingers as straight as possible -- instead of curled -- and using full arm movements --instead of finger and wrist contortions. This supposedly helps your arms and hands maintain a natural orientation.

As a professional, I am very concerned with these issues and I try to follow preventive measures against RSI as much as possible. I recommend others to do the same. Nevertheless, your tip was a good start for me to learn about key mappings.

Why are you baffled about? Vim is about fast and efficient writing, if you move your hands around in order to reach keys that's slowing you down. I don't deny the possiblity of developing some health condition but that's something the user has to make special "accomodations" about and it is not the goal of vim.

Remap Ctrl instead

Why remap so many keys just because you have to turn your hand for Ctrl? Remap Ctrl key instead. I do that on every system I use.

On any modern UNIX that uses X do:

setxkbmap -option ctrl:swapcaps

and your CapsLock key will become Ctrl, while Ctrl will become CapsLock, just like on good old Sun keyboards. That position is right next to the pinky finger, and feels really naturally. Considering that Bill Joy wrote vi and founded Sun, it's not a surprise that Sun keyboards were so ideally suited to vi. :-)

On older UNIX systems store this in a file:

! Swap Caps_Lock and Control_L
remove Lock = Caps_Lock
remove Control = Control_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Caps_Lock
add Control = Control_L

and execute that file with

xmodmap filename

Probably the best thing is to put one of these commands in .xsession or equivalent file. Red Hat Linux and Fedora will execute by default .Xkbmap and .Xmodmap. In such a case it is enough to put xmodmap commands in .Xmodmap file, and only -option ctrl:swapcaps in .Xkbmap. Of course you need only one of these two files.

In fact, I doubt that you'll do it, since you are already used to your mappings. But I do not recommend your tip to anybody else. I have put this detailed description here for other people who are frustrated with the position of Ctrl key, yet do not know how to change it.

Comments

If the Ctrl key is too far away for your thumb, try using your little finger.


Advertisement