[comp.editors] how do I do this in vi?

news@massey.ac.nz (USENET News System) (04/16/91)

Couple of questions of commands under VI?

1) Copy and paste every line in a file, for eg.

-r    87636 Apr  1 03:02 ./app/00app-abstracts.abs
-r      279 Apr  1 03:04 ./apple/00apple-abstracts.abs
-r     1299 Apr  1 03:03 ./apple/code/00code-abstracts.abs
-r     3687 Apr  1 03:03 ./apple/doc/00doc-abstracts.abs
-r     2064 Apr  1 03:03 ./apple/hin/00hin-abstracts.abs

-r    87636 Apr  1 03:02 ./app/00app-abstracts.abs
-r    87636 Apr  1 03:02 ./app/00app-abstracts.abs
-r      279 Apr  1 03:04 ./apple/00apple-abstracts.abs
-r      279 Apr  1 03:04 ./apple/00apple-abstracts.abs
-r     1299 Apr  1 03:03 ./apple/code/00code-abstracts.abs
-r     1299 Apr  1 03:03 ./apple/code/00code-abstracts.abs
-r     3687 Apr  1 03:03 ./apple/doc/00doc-abstracts.abs
-r     3687 Apr  1 03:03 ./apple/doc/00doc-abstracts.abs

2) Insert a blank line after every line. For eg

-r    87636 Apr  1 03:02 ./app/00app-abstracts.abs
-r      279 Apr  1 03:04 ./apple/00apple-abstracts.abs
-r     1299 Apr  1 03:03 ./apple/code/00code-abstracts.abs
-r     3687 Apr  1 03:03 ./apple/doc/00doc-abstracts.abs

to become

-r    87636 Apr  1 03:02 ./app/00app-abstracts.abs

-r      279 Apr  1 03:04 ./apple/00apple-abstracts.abs

-r     1299 Apr  1 03:03 ./apple/code/00code-abstracts.abs

-r     3687 Apr  1 03:03 ./apple/doc/00doc-abstracts.abs

Thanx
Raminder Singh

tchrist@convex.COM (Tom Christiansen) (04/16/91)

From the keyboard of R.Singh@massey.ac.nz (R. Singh):
:Couple of questions of commands under VI?

>1) Copy and paste every line in a file, for eg.

:%s/.*/&^M&/

>2) Insert a blank line after every line. For eg

:%s/$/^M/


You have to precede those control-M's with a control-V.

I don't think that vi is necessarily the right tool for this.  
I'd use sed or awk or perl.  Perl offers the advantage of 
in-place edits: 

For example, for the first case:

    perl -n -i.bak -e 'print "$_$_"' file1 file2 file3 ...

and for the second: 

    perl -n -i.bak -e 'print "$_\n"' file1 file2 file3 ...

The old version will be stored in file.bak in case of goofs.

--tom

peter@ficc.ferranti.com (Peter da Silva) (04/16/91)

In article <1991Apr15.223037.23316@massey.ac.nz> R.Singh@massey.ac.nz (R. Singh) writes:
> 1) Copy and paste every line in a file, for eg.

:g/^/copy.

> 2) Insert a blank line after every line. For eg

You have to be in EX mode for this, so hit Q:

g/^/a\
\
.
-- 
Peter da Silva.  `-_-'  peter@ferranti.com
+1 713 274 5180.  'U`  "Have you hugged your wolf today?"

em@dce.ie (Eamonn McManus) (04/16/91)

tchrist@convex.COM (Tom Christiansen) writes:
>>1) Copy and paste every line in a file, for eg.
>:%s/.*/&^M&/
>>2) Insert a blank line after every line. For eg
>:%s/$/^M/

This isn't guaranteed to work in all versions of vi.  The most portable
way to do, e.g., 2) is to escape to ex (with Q) and do
%s/$/\
/
The idea of allowing ^M to mean newline on the RHS of a substitute was
introduced, according to the comments, "to get rid of the last reason
for using ex" (or words to that effect).  In my view it is ill-conceived
because it is counterintuitive -- you have to use \^M to substitute in a
real ^M.  A proper solution would have been to allow : escapes from vi
to contain more than one line, so that the solution above would work
from vi too.

,
Eamonn

tr@samadams.princeton.edu (Tom Reingold) (04/19/91)

In article <1991Apr15.223037.23316@massey.ac.nz> R.Singh@massey.ac.nz
(R. Singh) writes:

$ Couple of questions of commands under VI?
$ 
$ 1) Copy and paste every line in a file, for eg.
$ 
$ -r    87636 Apr  1 03:02 ./app/00app-abstracts.abs
$ -r      279 Apr  1 03:04 ./apple/00apple-abstracts.abs
$ -r     1299 Apr  1 03:03 ./apple/code/00code-abstracts.abs
$ -r     3687 Apr  1 03:03 ./apple/doc/00doc-abstracts.abs
$ -r     2064 Apr  1 03:03 ./apple/hin/00hin-abstracts.abs
$ 
$ -r    87636 Apr  1 03:02 ./app/00app-abstracts.abs
$ -r    87636 Apr  1 03:02 ./app/00app-abstracts.abs
$ -r      279 Apr  1 03:04 ./apple/00apple-abstracts.abs
$ -r      279 Apr  1 03:04 ./apple/00apple-abstracts.abs
$ -r     1299 Apr  1 03:03 ./apple/code/00code-abstracts.abs
$ -r     1299 Apr  1 03:03 ./apple/code/00code-abstracts.abs
$ -r     3687 Apr  1 03:03 ./apple/doc/00doc-abstracts.abs
$ -r     3687 Apr  1 03:03 ./apple/doc/00doc-abstracts.abs

I probably wouldn't use vi.  I might use

	awk '{print
	print}' file

$ 2) Insert a blank line after every line. For eg
$ 
$ -r    87636 Apr  1 03:02 ./app/00app-abstracts.abs
$ -r      279 Apr  1 03:04 ./apple/00apple-abstracts.abs
$ -r     1299 Apr  1 03:03 ./apple/code/00code-abstracts.abs
$ -r     3687 Apr  1 03:03 ./apple/doc/00doc-abstracts.abs
$ 
$ to become
$ 
$ -r    87636 Apr  1 03:02 ./app/00app-abstracts.abs
$ 
$ -r      279 Apr  1 03:04 ./apple/00apple-abstracts.abs
$ 
$ -r     1299 Apr  1 03:03 ./apple/code/00code-abstracts.abs
$ 
$ -r     3687 Apr  1 03:03 ./apple/doc/00doc-abstracts.abs
$ 
$ Thanx
$ Raminder Singh

In awk, I would do

	awk '{print $0, "\n"}' file
--
        Tom Reingold
        tr@samadams.princeton.edu  OR  ...!princeton!samadams!tr
        "Warning: Do not drive with Auto-Shade in place.  Remove
        from windshield before starting ignition."

mcohen@amsaa-cleo.brl.mil (Marty Cohen) (04/22/91)

In article <exex@dce.ie> em@dce.ie (Eamonn McManus) writes:
>The idea of allowing ^M to mean newline on the RHS of a substitute was
>introduced, according to the comments, "to get rid of the last reason
>for using ex" (or words to that effect).  In my view it is ill-conceived
>because it is counterintuitive -- you have to use \^M to substitute in a
>real ^M.

^M is usually generated by the <CR> or Enter key on terminals.
On a unix system this is taken to be end-of-line (depending on
stty options selected), which is ordinally represented in a file
by ^J.  Ie. Control-M becomes control-J before it gets to vi.
The way to prevent this is to prefix it with control-V on BSD
systems or "\" on ATT systems.  Note that these prefixes may have
meaning to vi as well, in which case you would have to double up
on them.  Am I wrong about this?  Does vi disable this mode of
the terminal handler?
-- 
--
Marty Cohen mcohen@brl.mil  {uunet|rutgers}!brl!mcohen
Custom House Rm 800, Phila. PA 19106 (215)597-8377

hansm@cs.kun.nl (Hans Mulder) (04/24/91)

In <2243@amsaa-cleo.brl.mil> mcohen@amsaa-cleo.brl.mil (Marty Cohen) writes:

>Ie. Control-M becomes control-J before it gets to vi.
>Am I wrong about this?  Does vi disable this mode of the terminal handler?

Yes, you are wrong.  Yes, vi disables this mode.

In fact control-M and control-J are both cursor motion commands in vi,
and do different things.  Control-J aka Linefeed move the cursor straight
down (if possible), just like j, control-N and down-arrow.
Control-M aka Return moves the cursor to the first non-whitespace character
on the next line (if there is one), just like + and 2_.

You might try things out before you post.

--
Have a nice day,

Hans Mulder	hansm@cs.kun.nl

fin@norge.unet.umn.edu (Craig A. Finseth) (06/26/91)

I have seen lots of articles complaining about how big Emacs is and
how pervasive and small and simple vi is.  I would like the best of
both worlds.  Does anybody have a set of vi macros that emulates the
Emacs command set?

[ Lots of (:-)s for the humor-impaired. ]

Craig A. Finseth			fin@unet.umn.edu [CAF13]
Networking Services			+1 612 624 3375 desk
Computer and Information Services	+1 612 625 0006 problems
University of Minnesota			+1 612 626 1002 FAX
130 Lind Hall, 207 Church St SE
Minneapolis MN 55455-0134, USA

elliss@kira.egr.msu.edu (Stew Ellis) (06/27/91)

fin@norge.unet.umn.edu (Craig A. Finseth) writes:

>I have seen lots of articles complaining about how big Emacs is and
>how pervasive and small and simple vi is.  I would like the best of
>both worlds.  Does anybody have a set of vi macros that emulates the
>Emacs command set?

>[ Lots of (:-)s for the humor-impaired. ]

>Craig A. Finseth			fin@unet.umn.edu [CAF13]
>Networking Services			+1 612 624 3375 desk
>Computer and Information Services	+1 612 625 0006 problems
>University of Minnesota			+1 612 626 1002 FAX
>130 Lind Hall, 207 Church St SE
>Minneapolis MN 55455-0134, USA


Why not try jove?  It is a reasonable subset of emacs, with some extensibility
through keyboard- and named- macros.  Is is easier for a c programmer to add
c code than to learn lisp.  OS commands can be used as pipes for regions of
text in the edit buffer: I routinely define a region of a a space or two and
pipe it through date to get a date in a code comment or piece of mail
(Wed Jun 26 23:57:04 EDT 1991).  I also used pr to create a double-columned
help file by filtering regions.  Jove can parse C or grep -n errors in a
window.  Best of all, all of the code, docs and all, fits on one DOS HD floppy, maybe without even being 
compressed.  The ls for vi and jove on a SUN 3, SunOS4.1 follows:

solo> l /usr/ucb/vi
-rwxr-xr-x  7 root       155648 Feb  8  1990 /usr/ucb/vi
solo> l /usr/local/bin/jove
-rwxr-xr-x  1 stew       180224 Feb 12 13:28 /usr/local/bin/jove
solo>

It is not perfect and has some bugs, but for many people for whom the emacs
command set is more important than the feeping creaturism of GNU emacs, it is
a much more integrated product than uemacs.  

------------------------------------------------------------------------

                                             _________________________________
  R.Stewart (Stew) Ellis                    / _______________________________/
  Assoc. Prof. of Social Science           / /      ______  ____________  __
  Dept. of Humanities & Social Science    / /      /___  / / ___  ___  / / /
  1700 W. Third Avenue                   / /          / / / /  / /  / / / /
  Flint, MI 48504                       / /__________/ / / /  / /  / / / /
  313-762-9765 Office                  /______________/ /_/  /_/  /_/ /_/

  elliss@frith.egr.msu.edu            ENGINEERING & MANAGEMENT INSTITUTE        

  "Apple Macintosh, the closed system for people with supposedly open minds."
    - plagiarized from someone else on the net
  "How you gonna do it? OS/2 it!" - stupid IBM ad 
  "Have you ever heard anything so half-OSsed?" - me