Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #327 - Key mappings

Created: September 13, 2002 17:57 Complexity: basic Author: Nithin Version: 6.0 Karma: 2/15 Imported from: Tip#327

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



Bye,

Nithin.

Comments

Hello Nithin,

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.

Regards,

Eddy Young

young--AT--intnet.mu , September 20, 2002 1:57


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.

rumcho at yahoo dot com , June 25, 2003 14:36


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.

zvezdan--AT--cs.wm.edu , December 10, 2003 16:59


These mappings are brilliant mate!

As for "risk of RSI" ... I think anything that makes typing more comfortable LESSENS the risk of RSI.

Cheers! Ethan

emallove--AT--yahoo.com , December 14, 2003 12:35


I agree with the poster of the first additional comment; it may be because I'm a self-taught typist (I use all fingers of my right hand and one ot two of my right hand, and I let my hands "float" more or less freely over the keyboard) or because I learnt piano before I learnt Vim (no serious or even half-serious pianist will try to use the whole keyboard with no hand movement) :-).

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

Regards, Tony.

antoine.mechelynck--AT--belgacom.net , August 23, 2004 16:30


Advertisement