Loading ...
Sorry, an error occurred while loading the content.

Re: s/// with arithmetic

Expand Messages
  • Stahlman Family
    This reminds me of the problem I was having the other day, when I needed to do floating point arithmetic with timestamps on a bus log file (Subject: Vimrun
    Message 1 of 9 , May 4, 2005
    • 0 Attachment
      This reminds me of the problem I was having the other day, when I needed to
      do floating point arithmetic with timestamps on a bus log file (Subject:
      "Vimrun steals focus from other applications"). (OK, I admit that was a
      shameless ploy to attract attention to a post that appears to have been
      overlooked...) Seriously, however, Vim is the most powerful tool I have ever
      used for transforming text files from one shape to another. While it is
      possible to come up with many workarounds for both floating point and
      hexadecimal numbers (e.g., viml functions, perl, python interfaces, etc...),
      is not the processing of text files containing both float and hex format
      numbers common enough to warrant inclusion of code for handling both in the
      viml interpreter? Just a thought... I know it's been mentioned before.

      Thanks,
      Brett Stahlman

      ----- Original Message -----
      From: "Hari Kishore A J" <harikishore@...>
      To: <vim@...>
      Sent: Wednesday, May 04, 2005 4:06 AM
      Subject: Re: s/// with arithmetic


      On 5/4/05, Gary Johnson <garyjohn@...> wrote:
      > Not any straightforward way that I know of. Even if you could put
      > "0x" in front of the number before adding to it, the result would be
      > in decimal.
      >
      > Someone wrote a function to do hexadecimal math and posted it to
      > this list a few months ago. You could try searching the archives
      > for it.
      >
      > OK, I just searched for it. It might be the thread "arithmetic
      > task" that took place in May 2004.

      Thanks a lot Gary. That thread was very useful. Though it didn't have
      a straight answer, I took clue from it and finally this solved my
      problem

      s/my_regex/\=Nr2Hex(('0x'.submatch(2))+8)/

      where Nr2Hex is an example function given in h: eval-examples (eval.txt)

      Thanks a lot guys for the help

      --Kishore
    Your message has been successfully submitted and would be delivered to recipients shortly.