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

Re: Fwd: filter speed

Expand Messages
  • Benji Fisher
    ... Why not give Perl the whole line and let it do all the processing? This might be faster. If you set up your Perl one-liner (maybe a two-liner, now) as a
    Message 1 of 3 , Dec 29, 2003
    • 0 Attachment
      On Sun, Dec 28, 2003 at 09:29:58PM -0800, send, send, send, send junk, junk, junk, junk wrote:
      >
      > My immediate goal is to apply a function to an individual floating point
      > number quickly. To do this, I couldn't use :let, because the expression
      > parser does not seem to work on floats (docs seem to corroborate).
      > As a result, I used a macro to isolate a single floating point number
      > of interest from the rest of the row. This was necessary because as
      > is now acknowledge in the doc "motion" will not isolate text from the
      > rest of the line when used with an external filter. I then used a perl one-
      > liner to handle the expression and then added some J's to the macro
      > to put the line back together. This allowed me to perform my floating
      > point operations within a row with a single keystroke. The problem is
      > that it takes a few hundred milliseconds, and when I use the newly
      > created macro within larger macros, the speed becomes prohibitively
      > slow.

      Why not give Perl the whole line and let it do all the processing?
      This might be faster. If you set up your Perl one-liner (maybe a
      two-liner, now) as a filter, you could use :!!{filter} to call it.

      :help filter

      > I know Vim is like perl and there is undoubtedly more than one way
      > to do just about anything. If anyone can suggest a better way to
      > process some text within a line and/or a better way to work with
      > floating point numbers, I would be most appreciative.

      Have you tried something like this? After selecting the floating
      point number in Visual mode (it sounds like you know enough to do that
      much from a script) try (starting in Visual mode)

      c<C-R>=system('echo -n "#' . @" . '#"')<CR>

      (Type the <C-R> and <CR> literally if defining a :vmap ; each represents
      a single character if you are testing this interactively.) If, for
      example, you have "123.456" selected in Visual mode, this passes the
      string "#123.456#" to the system echo command (with the -n flag, to
      suppress the trailing EOL character) and puts the output in your buffer.
      Replace 'echo -n' with your Perl script to get something useful (and
      leave off the "#" characters). This may not be much faster, but it
      avoids splitting and re-joining the line.

      HTH --Benji Fisher
    Your message has been successfully submitted and would be delivered to recipients shortly.