by simon baird

Tuesday, September 09, 2008

Vim trick

1. Lets say you want to insert some text at an exact column. Try the following:

Put 100 spaces at the end of the line so that the | command works
100A<Space><Esc>

Move to the column you want
75|

Delete all those extra spaces and insert something
C

Tricky eh?


2. Suppose you wanted to record that as a macro so you could do it many times:

To record a macro in the q register:
qq0100A<Space><Esc>75|C",<Esc>0jq

Run it once
@q

Run it 10 times
10@q

No comments: