Inserting a character in certain column

Alexandra Zaharia f0rg3r at gmail.com
Mon Feb 25 12:39:40 UTC 2008


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

HTH,

Alex.




More information about the ubuntu-users mailing list