How to specify hex value in substitute command

1,817 views
Skip to first unread message

Roy Fulbright

unread,
Aug 23, 2008, 10:25:59 AM8/23/08
to vim...@googlegroups.com
I am trying to replace the value hexadecimal 96 in my file, but cannot figure out how to specify it in the substitute command. I have tried :s/x'96'/-/, :s/\x96/-/, and :s/x{96}/-/ but none of these worked (I get 'pattern not found' message). I tried :help hex but did not find anything that helped. Can someone please show me how to do this?
 
Thanks.


Get ideas on sharing photos from people like you. Find new ways to share. Get Ideas Here!

Roy Fulbright

unread,
Aug 23, 2008, 11:38:27 AM8/23/08
to vim...@googlegroups.com
Kept looking and found:
 
":help i_CTRL-V_digit" via google search, which is what I needed.
 
The substitute command is entered as follows:
 
:s/<C-V>x96/-/       (Note: Use <C_Q> instead of <C-V> for MS Windows)


 

Ag. D. Hatzimanikas

unread,
Aug 23, 2008, 12:09:39 PM8/23/08
to vim...@googlegroups.com
On Sat, Aug 23, at 11:38 Roy Fulbright wrote:
>
> I am trying to replace the value hexadecimal 96 in my file, but cannot
> figure out how to specify it in the substitute command. I have tried
> :s/x'96'/-/, :s/\x96/-/, and :s/x{96}/-/ but none of these worked (I
> get 'pattern not found' message). I tried :help hex but did not find
> anything that helped. Can someone please show me how to do this?
> Thanks.
>
> Kept looking and found:
>
> ":help i_CTRL-V_digit" via google search, which is what I needed.
>
> The substitute command is entered as follows:
>
> :s/<C-V>x96/-/ (Note: Use <C_Q> instead of <C-V> for MS Windows)
>

This is also seems to work:

:s/[\x96]/-/

documented under :help /\]

But I can't find a way to do it the other way around, search for something
and substitute with a hex number (without using C-V).

Regards,
Ag.

Teemu Likonen

unread,
Aug 23, 2008, 1:30:01 PM8/23/08
to vim...@googlegroups.com
Ag. D. Hatzimanikas wrote (2008-08-23 19:09 +0300):

> This is also seems to work:
>
> :s/[\x96]/-/

> But I can't find a way to do it the other way around, search for


> something and substitute with a hex number (without using C-V).

We can replace with an expression and use double-quoted string constant
there. It allows entering hexadecimal numbers:

s/something/\="\x96"/

See

:help sub-replace-expression
:help expr-string

Ag. D. Hatzimanikas

unread,
Aug 23, 2008, 1:44:01 PM8/23/08
to vim...@googlegroups.com

Thanks Teemu, I was missing the quotes in the sub-replace-expression.

Regards,
Ag.

Teemu Likonen

unread,
Aug 23, 2008, 3:05:07 PM8/23/08
to vim...@googlegroups.com
Ag. D. Hatzimanikas wrote (2008-08-23 20:44 +0300):

> [...]

By the way, your mail client (mutt) keeps adding Re:'s to the Subject
field. In a thread it will go "Re: Re: Re: Re:" etc. By default mutt
recognizes this common subject prefix and does not add new ones. Have
you changed the value of reply_regexp option?

Ag. D. Hatzimanikas

unread,
Aug 23, 2008, 7:07:34 PM8/23/08
to vim...@googlegroups.com
Hi Teemu,

That was tricky to find out (what in the h..l has happened), because I
didn't change the default regexp for a while, in fact I don't thing I
ever touched that variable in the mutt config.

But, I've recently introduced a procmail rule to modify the "Subject"
header, by inserting a tag with the name of the mailing list(s) (if
there is a matched mailing list); so I could tag them easily or limit
the view to specific mailing lists by using the limit command in mutt.

Naturally the default 'reply_regexp', failed to match the tags, see the
subject line after procmail filtering:

Subject: [vim_use] RE: How to specify hex value in substitute command

and the regexp:

reply_regexp="^(re([\\[0-9\\]+])*|aw):[ \t]*"


I've already took measures, extra measures in fact. :)
Besides that I've changed the 'reply_regexp' a bit, I thought I have to
protect my public image and so - as a plus - I've trusted once again the
vim regexp machine, to match and *eliminate* any extra re:'s.

Thanks for noticing.

Regards,
Ag.

Teemu Likonen

unread,
Aug 24, 2008, 1:37:39 AM8/24/08
to vim...@googlegroups.com
Ag. D. Hatzimanikas wrote (2008-08-24 02:07 +0300):

> But, I've recently introduced a procmail rule to modify the "Subject"
> header, by inserting a tag with the name of the mailing list(s) (if
> there is a matched mailing list); so I could tag them easily or limit
> the view to specific mailing lists by using the limit command in mutt.

Ah, ok. I just configure procmail to move mailing list messages to
different mailboxes and use mutt's mailboxes command to tell it which
mailboxes receive mail. Like this:

.procmailrc:

:0
* List-Id: <vim_use.googlegroups.com>
vim-use/

.muttrc:

mailboxes =vim-use

Christian Ebert

unread,
Aug 24, 2008, 3:50:43 AM8/24/08
to vim...@googlegroups.com
* Teemu Likonen on Sunday, August 24, 2008 at 08:37:39 +0300

Perhaps one should mention as a caveat that this rule is for
Maildir. Otherwise you need locking -- :0: -- and no slash at the
end.

As I am lazy I'm using a recipee that catches most of the lists
I'm subscribed to automatically:

:0
*$ ^List-Post:.*mailto:\/[^@]+
Lists/$MATCH/

c
--
Was heißt hier Dogma, ich bin Underdogma!
[ What the hell do you mean dogma, I am underdogma. ]

_F R E E_ _V I D E O S_ -->> http://www.blacktrash.org/underdogma/

Karthik GVS

unread,
Aug 24, 2008, 2:58:20 PM8/24/08
to vim...@googlegroups.com
On Sun, 24 Aug 2008 09:50:43 +0200 Christian Ebert <black...@gmx.net> wrote:
> * Teemu Likonen on Sunday, August 24, 2008 at 08:37:39 +0300
> > Ag. D. Hatzimanikas wrote (2008-08-24 02:07 +0300):
> >> But, I've recently introduced a procmail rule to modify the "Subject"
> >> header, by inserting a tag with the name of the mailing list(s) (if
> >> there is a matched mailing list); so I could tag them easily or limit
> >> the view to specific mailing lists by using the limit command in mutt.
> >
> > Ah, ok. I just configure procmail to move mailing list messages to
> > different mailboxes and use mutt's mailboxes command to tell it which
> > mailboxes receive mail. Like this:
> >
> > .procmailrc:
> >
> > :0
> > * List-Id: <vim_use.googlegroups.com>
> > vim-use/
>
> Perhaps one should mention as a caveat that this rule is for
> Maildir. Otherwise you need locking -- :0: -- and no slash at the
> end.
>
> As I am lazy I'm using a recipee that catches most of the lists
> I'm subscribed to automatically:
>
> :0
> *$ ^List-Post:.*mailto:\/[^@]+
> Lists/$MATCH/

Thought it'd be useful to point out something I got from the procmail list.

Note: There are [<space><tab>] ranges in the regexes below which might have
been mangled before you see them.

--->8----cut here ----8<---
# originally from http://www.professional.org/procmail/listname_id.rc
#
# Generic Listname identification
# 20030517/1134 SBS Updated to handle quoted Sender text
# 20040210/2140 SBS Optimized to eliminate shell/sed in the fallback
# portion.
# 20080724 karthik added x-list to handle some mailman configs

# First, grab stuff based on common "extra" headers inserted by lists,
# including RFC-2369 and RFC-2919 specified headers, compensating for
# text comments which have been encountered on some lists.

:0
* 9876543210^0 ^(Sender:[ ]*owner-|X-(BeenThere|list):[ ]*|Delivered-To:[ ]*mailing list )\/[-A-Za-z0-9_+]+
* 9876543210^0 ^(List-Post:[ ]*(<mailto:)?|List-Owner:[ ]*(<mailto:)?owner-)\/[-A-Z0-9_+]+
* 9876543210^0 ^Sender:.* List"? <(mailto:)?\/[-A-Z0-9_+]+
{
LISTNAME=$MATCH
}

# The second and third conditions were found in posts from Bart Schaefer
# dated 2002-07-18 - these optimize this fallback recipe so that it
# doesn't require the use of a shell, pipe, and sed to eliminate the -owner
# suffix.
#
# first, get the owner address (if the sender follows that syntax)
# Grab everything up through the last hyphen
# Grab everything except that last hyphen
# This is optimized to be one recipe, since MATCH will assume the set value
# after each condition line, and if the FIRST condition matches, the two that
# follow it definatley should.
:0E
* ^Sender:[ ]*\/[-A-Z0-9_+]+-owner
* MATCH ?? ^^\/.+-
* MATCH ?? ^^\/([^-]|-[^-])+
{
LISTNAME=$MATCH
}
--->8----cut here ----8<---


Karthik

--
GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion!
http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196

Reply all
Reply to author
Forward
0 new messages