Good vim tip

Joel Hammer Joel
Mon May 17 11:34:44 PDT 2004


This is so good I just had to pass it along.
For those who use vi(m), it is a nuisance to have to hit the esc key each
time you are done inserting text. So, in my .vimrc, I reprogrammed my ;
key to replace the esc key in the insert mode:

map! ; ^[l 

This works great. The only two problems are:
1. How to type a ; ?
2. Scrambled text when you past in text which has ;'s in it.

Problem one is solved by:
a) Either using the [cntrl]-v ; sequence while in the insert mode, or:
b) Programming a function key for this sequence of commands:
map! <F2> ^[:set noremap^Ma;^[:set remap^Ma   

I must say, I don't fully understand option b, but someone on this list
gave it to me and it works great.

The second problem, how to paste in text with a ; in it had me stumped.
I had no luck trying to use function keys to toggle this definiton on and
off.
But, I realized, by pure happenstance, that the r command reads in text and
doesn't worry about mapped keys. 
So, using the magic of xclip, I reprogrammed a function key in my .vimrc
file for the following:

:r<Space>!<Space>xclip<Space>-o^M<Space>  

This nicely reads in the current clipboard without looking at key mapping.

Ahh...
The pain eases.

Now, it might just be worth my while to figure out how the klipper works.

Joel





More information about the Linux-users mailing list