NetBSD-Users archive

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

Re: stupid question on vi



On Sun, 2025-02-23 at 06:44 +0000, RVP wrote:
> On Sat, 22 Feb 2025, Dave Tyson wrote:
> 
> > I have a file which has some hex characters 0x80 and higher.
> > 
> > I am trying to search for them so I can replace them. I can see
> > them
> > and they appear, for example, like \x93 on the screen and occupy a
> > single character.
> > 
> 
> nvi(1) has a poorly-documented Ctrl-X key which can be used to both
> enter and
> search for (after a fashion) arbitrary chars. To input, let's say,
> \x93, do:
> 
> $ LC_CTYPE=C vi foo.txt			# must use "C" locale
> i					# insert mode
> <Ctrl-X>93<ESC>				# input single:  \x93
> <Ctrl-X>94<Ctrl-X>A1<ESC>		# input 2 chars: \x94\xA1
> ...
> 
> For searching:
> 
> $ LC_CTYPE=C.UTF-8 vi foo.txt		# must use UTF-8 locale for
> some reason...
> /<Ctrl-X>93<ENTER>			# search for: \x93
> 
> A (comparatively) less bug-ridden technique is to search using
> negated
> char.-classes:
> 
> [^[:print:][:cntrl:]]			# non-ASCII chars.
> 
> That works, except that \x00 is _not_ regarded as a control-char.
> 
> -RVP

The search suggestion worked perfectly! Using Ctrl-X is a trick I was
unaware of and has been committed to memory!

I searched for 0xba (a Degree symbol) - I needed to see the context to
work out if it was temperature or an angle!

Thanks to the other responders I hadn't thought of using the META key -
will probably have a play with that in the future. I wasn't aware of
Grok3 but I have been avoiding AI stuff for now!

Cheers,
Dave

 


Home | Main Index | Thread Index | Old Index