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 possibility of developing some health condition but that's something the user has to make special "accommodations" about and it is not the goal of Vim.

Using a macintosh computer, the main modifier key is the command key, and I find it a lot easier using my thumb to press the towards-the-center-of-the-keyboard command key than using my little finger for the control key. An option could be to remap to alt/window/control/etc keys so that the control key is the most central. This would be useful outside of vim as well. Then you wouldl have the caps lock available to use as an escape key or backspace key or whatever.

Comments

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


Advertisement