Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I was playing vimgolf (very addictive by the way) and I can't understand one of the solutions to this challenge http://vimgolf.com/challenges/4d1a34ccfa85f32065000004

The challenge is to convert this text:

Make the pairs of lines match up by making each second line same as first:

# Appending text:
The name "Vim" is an acronym for "Vi IMproved"
The name "Vim" is an acronym for

# Editing text:
Vim is a text editor originally released by Bram Moolenaar in 1991 for the Amiga
Trivia: Vim is a text editor released by Bram Moolenaar in 1991 for the Amiga

# Deleting text:
Vim has a vi compatibility mode
Vim has a vi compatibility mode but when not in this mode Vim has many enhancements over vi

to this:

Make the pairs of lines match up by making each second line same as first:

# Appending text:
The name "Vim" is an acronym for "Vi IMproved"
The name "Vim" is an acronym for "Vi IMproved"

# Editing text:
Vim is a text editor originally released by Bram Moolenaar in 1991 for the Amiga
Vim is a text editor originally released by Bram Moolenaar in 1991 for the Amiga

# Deleting text:
Vim has a vi compatibility mode
Vim has a vi compatibility mode

My question is, how the second line of this solution works:

:g/#/+2d<CR>:<Up><BS><BS>1t.<CR>ZZ

and by second line I mean :g/#/+1t.

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

As you might already know :g/#/ runs a command for all the lines containig a #, which are the topics of the different challenges.

Now, as your 1st line has deleted the "wrong" line, the 2nd just copyies the remainding one

You are on the #-Line, you move one line ahead (+1) and copy (t) it to the current line (.)

Which leaves 2 identical lines.

share|improve this answer
    
Wait, so the 't' command in ex-mode is a synonym for 'co'? I see that vim 7.2 acts that way, but I can't find any documentation about the 't'/'co' equivalence. –  Bruce Ediger Dec 13 '11 at 19:15
2  
Just try :help :t –  Nikodemus Dec 13 '11 at 19:17
1  
Nikodemus answers my follow-on question correctly. I just want to note that in vi-mode ':help :t' gives you the t-to-co equivalence, while ':help t' gives you something about a "till" command. The extra colon is everything. –  Bruce Ediger Dec 13 '11 at 19:57
    
That's exactly what I don't understand. So t which is the same thing as co, here is used with range 1 and address .? –  Ali Dec 13 '11 at 20:04
1  
Well ... the range is 1 unless specified different. +1 is the position, 1 after the /#/. That line is copied to after the position given in the argument, which is . –  Nikodemus Dec 13 '11 at 22:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.