NetBSD-Users archive

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

Re: stupid question on vi



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


Home | Main Index | Thread Index | Old Index