mis-mapping in vi

mis-mapping in vi

Post by Phil Curr » Sun, 11 Nov 2001 13:10:37



I'm constantly moving/editing files back and forth between the Sun boxes at
school and my Mac OSX box at home. When I ftp the files over, the line
endings get messed up. I finally figured out that-

:s/^M/^M/g

will fix the problem. (the first is ctl-M, the second ctl-rtn)

I wanted to map an unused key to perform this action, so according to
directions I-

: map _ :s/^M/^M/g

but when I press a _ in command mode, it says "No previous regular
expression". Any ideas? TRhanks.
-Phil
--
Progress: The art of making the circles you are running in,
drift in the right direction.

 
 
 

mis-mapping in vi

Post by Rich Tee » Sun, 11 Nov 2001 14:51:54



> I'm constantly moving/editing files back and forth between the Sun boxes at
> school and my Mac OSX box at home. When I ftp the files over, the line
> endings get messed up. I finally figured out that-

If you ftp the file sin ASCII mode, the conversion will be
performed for you as the files get copied.

--
Rich Teer

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-online.net

 
 
 

mis-mapping in vi

Post by Phil Curr » Mon, 12 Nov 2001 01:16:50


Well, I do and it doesn't.
--
Minds are like parachutes... they work best when open.

----------



>> I'm constantly moving/editing files back and forth between the Sun boxes at
>> school and my Mac OSX box at home. When I ftp the files over, the line
>> endings get messed up. I finally figured out that-

> If you ftp the file sin ASCII mode, the conversion will be
> performed for you as the files get copied.

> --
> Rich Teer

> President,
> Rite Online Inc.

> Voice: +1 (250) 979-1638
> URL: http://www.rite-online.net

 
 
 

mis-mapping in vi

Post by Logan Sh » Mon, 12 Nov 2001 04:45:28






>> If you ftp the file sin ASCII mode, the conversion will be
>> performed for you as the files get copied.
>Well, I do and it doesn't.

Either your ftp client or server is broken, then.  That's the whole
point of ASCII mode.

On the other hand, MacOS X may have some kind of weird issue,
considering it's a combination of the Mac and Unix worlds and the
two have different line-end characters.  Do the Mac programs under
OS X use LF now, do the Unix programs use CR, or do they both use
different things?  If both line end characters are in use in
different situations, then the ftp client/server has no right answer
as to how to do the conversion.  On the other hand, if this is the
case, then _hopefully_ the OS provides some easy way of converting!

  - Logan
--
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos

 
 
 

mis-mapping in vi

Post by Phil Curr » Mon, 12 Nov 2001 10:24:24


OK... let me rephrase the question:
How can I map a _ character to perform a :s/e/E/g which if I <esc> : s/e/E/g
will change all the e's to E's in the first line.

Thanks.
-Phil
--
"The early bird may get the worm... but the second mouse gets the cheese."

----------






>>> If you ftp the file sin ASCII mode, the conversion will be
>>> performed for you as the files get copied.

>>Well, I do and it doesn't.

> Either your ftp client or server is broken, then.  That's the whole
> point of ASCII mode.

> On the other hand, MacOS X may have some kind of weird issue,
> considering it's a combination of the Mac and Unix worlds and the
> two have different line-end characters.  Do the Mac programs under
> OS X use LF now, do the Unix programs use CR, or do they both use
> different things?  If both line end characters are in use in
> different situations, then the ftp client/server has no right answer
> as to how to do the conversion.  On the other hand, if this is the
> case, then _hopefully_ the OS provides some easy way of converting!

>   - Logan
> --
> "In order to be prepared to hope in what does not deceive,
>  we must first lose hope in everything that deceives."

>                                           Georges Bernanos

 
 
 

mis-mapping in vi

Post by Logan Sh » Mon, 12 Nov 2001 16:28:16




>OK... let me rephrase the question:
>How can I map a _ character to perform a :s/e/E/g which if I <esc> : s/e/E/g
>will change all the e's to E's in the first line.

Type ":map _ :1s/e/E/g", then control-v, then hit
return twice.  I'm not sure why you want it to just
change the "e" to "E" in the first line, though.  If
you want to do it on all the lines, take out the "1".

Personally I wouldn't use the underscore, since it's
already defined.  I like to use things that start with "["
for my own commands, since lots of that isn't defined
already.  ("[[" is, but not anything else that I know of.)

  - Logan
--
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos

 
 
 

mis-mapping in vi

Post by Phil Curr » Tue, 13 Nov 2001 10:24:41






>>OK... let me rephrase the question:
>>How can I map a _ character to perform a :s/e/E/g which if I <esc> : s/e/E/g
>>will change all the e's to E's in the first line.

> Type ":map _ :1s/e/E/g", then control-v, then hit
> return twice. I'm not sure why you want it to just
> change the "e" to "E" in the first line, though.  If
> you want to do it on all the lines, take out the "1".

Because... since the line endings are messed up I only have 1 line.
One very long line.
Quote:

> Personally I wouldn't use the underscore, since it's
> already defined.  I like to use things that start with "["
> for my own commands, since lots of that isn't defined
> already.  ("[[" is, but not anything else that I know of.)

I chose _ because I thought it was undefined. Where can I find a list of
unused keys?
You make it sound like a cmd can be mapped to a multi key combo [? -- is
that true?

Now, for the exact question I asked above, your instructions work. Thanks.

Unfortunately I can't extend the pattern to accomplish my real goal which is
to map "s/<ctl-M>/<ctl-rtn>/g" to a key. If I enter that sequence in by hand
it replaces all the ^M in the file with hard carriage returns for a
particular file. When I try to map it I get the "No previous regular
expression" message.

Thanks but I'm still at square 1.
-Phil

 
 
 

mis-mapping in vi

Post by eric » Tue, 13 Nov 2001 22:53:50







> >>OK... let me rephrase the question:
> >>How can I map a _ character to perform a :s/e/E/g which if I <esc> : s/e/E/g
> >>will change all the e's to E's in the first line.

> > Type ":map _ :1s/e/E/g", then control-v, then hit
> > return twice. I'm not sure why you want it to just
> > change the "e" to "E" in the first line, though.  If
> > you want to do it on all the lines, take out the "1".

> Because... since the line endings are messed up I only have 1 line.
> One very long line.

> > Personally I wouldn't use the underscore, since it's
> > already defined.  I like to use things that start with "["
> > for my own commands, since lots of that isn't defined
> > already.  ("[[" is, but not anything else that I know of.)

> I chose _ because I thought it was undefined. Where can I find a list of
> unused keys?
> You make it sound like a cmd can be mapped to a multi key combo [? -- is
> that true?

> Now, for the exact question I asked above, your instructions work. Thanks.

> Unfortunately I can't extend the pattern to accomplish my real goal which is
> to map "s/<ctl-M>/<ctl-rtn>/g" to a key. If I enter that sequence in by hand

try escaping the ctrl characters with a \ in front of them.  Also try
inserting a ctrl-v in front of them.  map just replays the keystrokes so
when it hits the return it stops there which is why you get the error.

map _ s/C-vC-vC-vC-M/C-vC-vC-vC-J/g
or
map _ s/\C-vC-M/\C-vC-J/g

I am making the assumption that your <ctl-rtn> maps to ctl-J

also in my opinion I wouldn't worry about mapping over a key that has a
function that you don't use
if you have a newer vi

:viusage

will get you a list of currently bound keys

:map

will get you a list of keys that are mapped

_ is move to first non-blank

hth,

Eric

 
 
 

mis-mapping in vi

Post by eric » Tue, 13 Nov 2001 23:30:39








> > >>OK... let me rephrase the question:
> > >>How can I map a _ character to perform a :s/e/E/g which if I <esc> : s/e/E/g
> > >>will change all the e's to E's in the first line.

> > > Type ":map _ :1s/e/E/g", then control-v, then hit
> > > return twice. I'm not sure why you want it to just
> > > change the "e" to "E" in the first line, though.  If
> > > you want to do it on all the lines, take out the "1".

> > Because... since the line endings are messed up I only have 1 line.
> > One very long line.

> > > Personally I wouldn't use the underscore, since it's
> > > already defined.  I like to use things that start with "["
> > > for my own commands, since lots of that isn't defined
> > > already.  ("[[" is, but not anything else that I know of.)

> > I chose _ because I thought it was undefined. Where can I find a list of
> > unused keys?
> > You make it sound like a cmd can be mapped to a multi key combo [? -- is
> > that true?

> > Now, for the exact question I asked above, your instructions work. Thanks.

> > Unfortunately I can't extend the pattern to accomplish my real goal which is
> > to map "s/<ctl-M>/<ctl-rtn>/g" to a key. If I enter that sequence in by hand

> try escaping the ctrl characters with a \ in front of them.  Also try
> inserting a ctrl-v in front of them.  map just replays the keystrokes so
> when it hits the return it stops there which is why you get the error.

> map _ s/C-vC-vC-vC-M/C-vC-vC-vC-J/g
> or
> map _ s/\C-vC-M/\C-vC-J/g

hmmm escaping doesn't seem to be working very good either.  Have you
tried dos2unix the program?

do this on the command line

perl -pi.bak -e "s/\r/\n/mg" filename

you could bind it in your shell :)

it's the equiv of something like (this is a modified excerpt from the
perlrun man page)

                #!/usr/bin/perl
                $extension = '.bak';
                LINE: while (<>) {
                    if ($ARGV ne $oldargv) {
                        if ($extension !~ /\*/) {
                            $backup = $ARGV . $extension;
                        }
                        else {
                            ($backup = $extension) =~ s/\*/$ARGV/g;
                        }
                        rename($ARGV, $backup);
                        open(ARGVOUT, ">$ARGV");
                        select(ARGVOUT);
                        $oldargv = $ARGV;
                    }
                    s/\r/\n/mg;
                }
                continue {
                    print;  # this prints to original filename
                }
                select(STDOUT);

or if you want a shorter program to alias (also from the perlrun man
page)
                #!/usr/bin/perl -pi.orig
                s/\r/\n/mg;

Eric

 
 
 

mis-mapping in vi

Post by Logan Sh » Wed, 14 Nov 2001 11:49:04




>Because... since the line endings are messed up I only have 1 line.
>One very long line.

In that case, you're in trouble because "real" vi only allows you
a certain maximum line length.  So if you do this a lot, eventually
your file will get truncated.

If you're not using "real" vi and you're using vim instead, you probaby
want to check into the support that vim has for automatically
recognizing line endings and "doing the right thing"[1].

Quote:>I chose _ because I thought it was undefined. Where can I find a list of
>unused keys?

Good question.  vi documentation isn't the greatest.  I've been using
it for over 10 years, and I'm still finding about new things through
word of mouth.  :-)

Your first task is to figure out what version of vi you're using.  From
there you might take a look at http://www.thomer.com/thomer/vi/vi.html
and http://www.vi-editor.org/ .

Quote:>You make it sound like a cmd can be mapped to a multi key combo [? -- is
>that true?

Yes.  For example, in my ~/.exrc, I have the following:

        map [f {!}fmt^M

(It's a real control-M in my .exrc file.)  This allows me to just hit
"[f" in the middle of any paragraph of text (after hitting escape, of
course), and then vi will send it to "fmt" for formatting.  I also
have

        map [d :r!date^M

to read the date into the current buffer.  I like to use letters with
"[" because that makes the bindings a little less arbitrary.

Quote:>Unfortunately I can't extend the pattern to accomplish my real goal which is
>to map "s/<ctl-M>/<ctl-rtn>/g" to a key. If I enter that sequence in by hand
>it replaces all the ^M in the file with hard carriage returns for a
>particular file.

Well, as I mentioned earlier, this approach is unlikely to be useful,
so I'd just use Perl like someone else suggested.

  - Logan

[1]  As long as your opinion of "the right thing" is to let you edit
     the file and continue to use its line-end convention, instead of
     converting it to the native line-end convention.
--
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos

 
 
 

1. mis-mapped swap pages in linux-1.0

installed 1.0 on an everex 3000D w/ 5MB main memory, 12MB swap.
swap drive is hdb3 (maxtor 125MB on an ultrastor 15C caching ide controller).

problem: after using 10-20% of swap i start getting LOTS of mis-mapped
swap entry errors.  booting the 0.99.15 kernel fixes the problem.

both kernels were made with the same gcc 2.5.8, gmake 3.69, glibc 4.xx
(whatever's currently on sunsite today).

q: anyone else seen this?
q: any fixs?

thanx,

2. server does't match driver

3. mapping extended keyboard keys in vi/ksh

4. Can't get the mouse to work!

5. Mapping <Tab> key in vi or vim

6. starting pppd...

7. vi question - mapping a function key in .exrc file that uses a yanked word

8. Setup downloaded RH 7.0 in a WindowsMe machine

9. Conditional in .exrc for vi mappings???

10. EX, VI, AWK Guru needed? Mapping?

11. vi mapping question?

12. How do you map a <Tab> in vi ?

13. Key mapping for vi (vim).