Re: search/replace on a buffer?
- Peter Jay Salzman wrote:
> 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
> his question was: can you do a search and replace on a buffer?In VimSpeak, "buffer" refers to the entire file in memory. I think you
> 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!
want to manipulate a register, such as "z.
I think you want to enter Command mode to modify a register (or any String
variable). To warm up, try
:echo strpart(@z, 3)
:echo substitute(@z, '...', '', '')
: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