NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: stupid question on vi



On Sun, 23 Feb 2025, Dave Tyson wrote:
I have tried various incantations like
/^V\%x93

That's a vim "thing".

I have used sed to do do replacements fine

I think that's a perl "thing".

The escape sequence \xNN is not implemented in regex, but locally
in sed:

/usr/src/usr.bin/sed/compile.c
================================
[...]
static int
ston(char **pp, char *sp, int base)
{
        char *p = *pp, n;
        int r = cton(p[1], base);

        if (r == '?')
                return 0;

        p++;
        while ((n = cton(p[1], base)) != '?' && r < 255) {
                r = r * base + n;
                p++;
        }
        *sp = (char)r;
        *pp = p;
        return 1;
}
[...]
static int
unescape(char **pp, char **spp)
{
        char *p = *pp;
        char *sp = *spp;

        switch (*p) {
        case 'o':
                if (!ston(&p, sp, 8))
                        return 0;
                break;
        case 'd':
                if (!ston(&p, sp, 10))
                        return 0;
                break;
        case 'x':
                if (!ston(&p, sp, 16))
                        return 0;
                break;
[...]
================================

So as you can see, you can use octal and decimal also.

This is sadly not documented. And don't expect it to work in other
utilities like grep.

I wonder if this should be included in regex for homogeneity. It's
frustrating when something inside a regular expression has a meaning
in a tool, and has another in another tool on the same system,
especially with so basic and so used utilites like sed and grep.

I strongly recommend you to use UTF-8 and Compose(5) if you want
to search and see the context of these characters.

But RPV gave you exactly what you were asking for. Vi(1) is very
complete but I would expend some time reading
/usr/share/doc/reference/ref1/vi/vi.txt if you are going to use
nvi as your main text editor.

From: Robert Elz <kre%munnari.OZ.AU@localhost>
or holding the META key while typing ^S (0x13) (which
then might need a ^V prefix, as ^S tends to be special)

I've never used meta with ^S, I'm curious, how do you use it?
I tried and I can't get anything.

Regards.
adr

PS.
*********
I've encountered an intellectual problem in front of me.

Options:

1. Learn the tools I have at hand, use my mind, exercise my
creativity, interact with other people, have discussions, study
and learn, create new tools, change the approach, rethink the
problem itself...

2. Ask the Wizard of Oz.

The number of people that is going to choose 2 now... especially young
people...

We are so f*.


Home | Main Index | Thread Index | Old Index