[comp.editors] Is there a vi command to...

richt@meaddata.com (Rich Thompson) (05/09/91)

Is there any command in VI which will execute a "~" on every
character on the current line to the right of the current
character?

Thanks for any info anyone can give.

Rich
-- 
---
I bet you were expecting a disclaimer here, weren't you?

Richard Thompson                                  CE Systems Evolution
Mead Data Central                                   richt@meaddata.com
P.O. Box 933                                  ...!uunet!meaddata!richt
Dayton, Ohio  45401                           

tchrist@convex.COM (Tom Christiansen) (05/09/91)

From the keyboard of richt@meaddata.com (Rich Thompson):
:Is there any command in VI which will execute a "~" on every
:character on the current line to the right of the current
:character?

    map = y$mno^V^[P:s/./\~/g^V^M0"nDdd`n@n

you probably don't need the ^V's if this is in your
.exrc instead of just typed in.

--tom
--
Tom Christiansen		tchrist@convex.com	convex!tchrist
		"So much mail, so little time." 

weimer@garden.ssd.kodak.com (Gary Weimer (253-7796)) (05/10/91)

In article <1991May09.160949.12305@convex.com>, tchrist@convex.COM (Tom
Christiansen) writes:
|> From the keyboard of richt@meaddata.com (Rich Thompson):
|> :Is there any command in VI which will execute a "~" on every
|> :character on the current line to the right of the current
|> :character?
|> 
|>     map = y$mno^V^[P:s/./\~/g^V^M0"nDdd`n@n

Neat! So now we can do (from my new .exrc file):

" extensions for ~ command
"   macro called by all ~ macros
map ~_ mno^[P:s/./\~/g^M0"nDdd`n@n
map ~$ y$~_
map ~w yw~_
.
.
.

But using these brought up some interesting "features"

1) When I used the original = macro (even when I renamed it ~$), I could
   make one change to a line (let's say Line1), but the next 2 attempts
   to change Line1 failed with a beep (apparently at the `n). Every
   third attempt worked properly. If I changed Line1, then X other lines
   with the macro, I could then change Line1 again (Too lazy to figure
   out X). The 'u' command before changing Line1 the second time would
   undo all of the changes (not just the last one). If I use the = macro
   first, the ~$ macro above exibits (I think there's an 'h' in there
   somewhere) the same behavior. If I use the ~$ macro, I can modify the
   same line multiple times.

2) With both the original macro and my modified version, The ~ for the
   last character does not get executed until after the cursor is moved
   or another command is given. So if I start with:

abcdefg
  ^
  cursor here

   and do ~$, I get

abCDEFg
      ^
      cursor here

   Moving the cursor changes the g first. BUT typing ~ gives:

abCDEFG
      ^
      cursor here

   and now after moving the cursor it changes to:

abCDEFg


Assuming these are not universal for all implementations of vi, I am
running SunOS 4.1.1 on a Sparc I+ with Version SVR3.1 of vi.

Happy Debugging...

weimer@ssd.kodak.com ( Gary Weimer )

rosen@cbnewsb.cb.att.com (steven.b.rosen) (05/11/91)

In article <1991May10.165948.9707@ssd.kodak.com>, weimer@garden.ssd.kodak.com (Gary Weimer (253-7796)) writes:
> 
> In article <1991May09.160949.12305@convex.com>, tchrist@convex.COM (Tom
> Christiansen) writes:
> |> From the keyboard of richt@meaddata.com (Rich Thompson):
> |> :Is there any command in VI which will execute a "~" on every
> |> :character on the current line to the right of the current
> |> :character?
> |> 
> |>     map = y$mno^V^[P:s/./\~/g^V^M0"nDdd`n@n
 
Heres another way to skin this cat that I think is easier.

        :. s/./\u&/g
               ^^^--------change every char (.) with the uppercase of .
 
        You can also do \l to flip to lower case. 
        Finally there is a whole bunch of things you do with the 
        "search string" such as..

                :1,$ s/\<./\u&/g
                       ^^^--------find the char at the start of a word
                                  and flip its case to upper.


                ...steve... 


----------------------------------------
Steve Rosen               attmail!srosen
                      srosen@attmail.com
----------------------------------------

tchrist@convex.COM (Tom Christiansen) (05/11/91)

From the keyboard of rosen@cbnewsb.cb.att.com (steven.b.rosen):
:In article <1991May10.165948.9707@ssd.kodak.com>, weimer@garden.ssd.kodak.com (Gary Weimer (253-7796)) writes:
:> 
:> In article <1991May09.160949.12305@convex.com>, tchrist@convex.COM (Tom
:> Christiansen) writes:
:> |> From the keyboard of richt@meaddata.com (Rich Thompson):
:> |> :Is there any command in VI which will execute a "~" on every
:> |> :character on the current line to the right of the current
:> |> :character?
:> |> 
:> |>     map = y$mno^V^[P:s/./\~/g^V^M0"nDdd`n@n
: 
:Heres another way to skin this cat that I think is easier.
:
:        :. s/./\u&/g
:               ^^^--------change every char (.) with the uppercase of .
: 
:        You can also do \l to flip to lower case. 
:        Finally there is a whole bunch of things you do with the 
:        "search string" such as..
:
:                :1,$ s/\<./\u&/g
:                       ^^^--------find the char at the start of a word
:                                  and flip its case to upper.

the problem with your solution is that you lose the cursor position
and do it to the whole line.    mine goes through contortions to 
maintain this.  

:        :. s/./\u&/g

that would be much more efficiently executed as 

        :. s/.*/\U&/

--tom
--
Tom Christiansen		tchrist@convex.com	convex!tchrist
		"So much mail, so little time." 

richt@meaddata.com (Rich Thompson) (05/14/91)

Tom Christiansen sent me his solution a day or so ago and it worked for
me most of the time.  Unfortunately, unless I was in the first column of
a line, the dang thing would beep (which really annoyed me!).  So I played 
with it until I got a version that doesn't beep.  It is a couple of more
steps and may not be efficient but works just the same.  Here is is:

map = mno^[`ny$j0P:s/./\~/g^M0"nDdd`n@n`n

Rich

-- 
---
I bet you were expecting a disclaimer here, weren't you?

Richard Thompson                                  CE Systems Evolution
Mead Data Central                                   richt@meaddata.com
P.O. Box 933                                  ...!uunet!meaddata!richt
Dayton, Ohio  45401