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

Re: search/replace on a buffer?

Expand Messages
  • Benji Fisher
    ... [snip] ... In VimSpeak, buffer refers to the entire file in memory. I think you want to manipulate a register, such as z. ... I think you want to enter
    Message 1 of 2 , Aug 1, 2002
    • 0 Attachment
      Peter Jay Salzman wrote:
      >
      > hola,
      >
      > one of my students asked me a question i couldn't answer.
      >
      > at the bottom of the file, he has:
      >
      > -> :!top
      > -> :!nice -n10 planetary % &
      > -> :w
      >
      [snip]
      > his question was: can you do a search and replace on a buffer?
      >
      > in other words, i guess it would be something like:
      >
      > map <F1> mzG"zyy `z@z<CR>
      > ^
      > | this is where we'd get rid of "-> " in the z buffer
      >
      > does anybody know how to do this?
      >
      > before anyone asks, the goal isn't mapping a single key to save. it's
      > just to learn how to do a search/replace on a vim buffer.
      >
      > btw, this kid is a sophmore in highschool. he's going to be one awesome
      > vim user!

      In VimSpeak, "buffer" refers to the entire file in memory. I think you
      want to manipulate a register, such as "z.

      :help buffers
      :help registers

      I think you want to enter Command mode to modify a register (or any String
      variable). To warm up, try

      :echo @z
      :echo strpart(@z, 3)
      :echo substitute(@z, '...', '', '')

      :help expr-register
      :help strpart()
      :help substitute()
      :help functions() " in general

      To put this into your mapping,

      map <F1> mzG"zyy:let @z=strpart(@z,3)<CR>`z@z<CR>

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