Monday, April 2, 2018

Re: Search & replace with grep

You are trying to do something difficult which requires a lot of background. I can only offer some thoughts.

Use the part of the tip that I mentioned: two vnoremap commands after "Search for selected text, forwards or backwards". Do not use anything else.

\_s means space or tab or newline.

Visually select the three lines then press *

If you wanted to replace it with something simple you could do:

:%s//REPLACE/g

You want to add a capture so you would need to type:

:%s/
Ctrl-R /
/REPLACE/g

That is all in one line in the command line. The two keys Ctrl-R / inserts the value of the search register.

Before pressing Enter to execute the command, you have to edit it to insert the capture. I suggest typing the command into a temporary buffer where you can take your time to get it right. When finished you would have something like:

:%s/SEARCH/REPLACE/g

With the cursor on the line press Y to copy the whole line. Then switch to the buffer where you want to make the change and type @"

Typing @x executes the contents of register x. @" is the unnamed register (:help registers).

In this case the "g" flag (global) is not needed because there can only be one hit per line.

If you try all this and can't get the command to work, post the command you used.

John

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: