5

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.

1 Answer 1

4

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.

5
  • 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.
    – user732
    Dec 13, 2011 at 19:15
  • 2
    Just try :help :t Dec 13, 2011 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.
    – user732
    Dec 13, 2011 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, 2011 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 . Dec 13, 2011 at 22:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .