Inserting a character in certain column
jack
tdldev at gmail.com
Mon Feb 25 14:32:10 UTC 2008
On Mon, 2008-02-25 at 14:39 +0200, Alexandra Zaharia wrote:
> On 2/25/08, Szemerédy Gábor <gaborszem at eccf.su.ac.yu> wrote:
> > Hello list!
> > I need to insert a character in certain column in all rows of the file
> > using vi.
> > Please help
> >
>
> If I understand correctly, suppose you have the file
>
> aaaa
> bbbb
> cccc
> dddd
>
> and you want to turn it into
>
> aaaXYa
> bbbXYb
> cccXYc
> dddXYd
>
> Then here's what you have to do in vi:
>
> - position yourself on the first row - if * is the cursor, then in the
> given file your position should be:
> aaa*a
> bbbb
> cccc
> dddd
>
> - make sure you're in command (press <esc>) mode and press 'v' - this
> is for selecting text
>
> - hit 'j' 3 times - until you "select" what's below showed in '*':
>
> aaa*
> ****
> ****
> ****
>
> - now press <ctrl> and 'v'; your file will look like this:
>
> aaa*
> bbb*
> ccc*
> ddd*
>
> - now press <shift> and 'i':
>
> aaa*
> bbbb
> cccc
> dddd
>
> - now write the char(s) you need to insert, for instance 'XY':
>
> aaaXYa
> bbbb
> cccc
> dddd
>
> - now hit <esc> and you'll finally get your 'XY' inserted on the 4th
> column on each row:
>
> aaaXYa
> bbbXYb
> cccXYc
> dddXYd
>
> vi ist krieg! :-D
>
Alex~
Very cool! block marking is one of the lesser-known goodies in vi.
*Old school gold star* !
Jack
More information about the ubuntu-users
mailing list