Command to surround a character with spaces in vim

Posted by William Becker on Stack Overflow See other posts from Stack Overflow or by William Becker
Published on 2010-03-14T19:03:18Z Indexed on 2010/03/14 19:05 UTC
Read the original article Hit count: 167

Filed under:
|

I am trying to use vim properly - to aid me I've mapped my arrow keys to "" so that I am forced to use {hjlk} to move around.

This is causing me a problem when I want to just surround a character with spaces, eg:

"2+3" is better formatted "2 + 3"

Previously I would have put my cursor over the + and typed:

i[space][arrow-right][space][Esc]

That's 5 presses.

To do this without the arrow I seem to need to put the cursor over the + and go:

i[space][Esc]lli[space][Esc]

That's 8 presses.

I can convert the "li" into an "a" which reduces it to 7 presses:

i[space][Esc]la[space][Esc]

Short of writing this into a macro is there a better way of doing it? Is there some magic vim command which will allow me to do it in less than even 5 presses - and some way to generalise it so that I can do it to entire words or symbols, eg if I want to convert 3==4 to 3 == 4?

© Stack Overflow or respective owner

Related posts about vim

Related posts about vi