Monday, April 2, 2018

Re: Search & replace with grep

On Monday, 2 April 2018 06:11:20 UTC+2, JohnBeckett wrote:
> On Sunday, April 1, 2018 at 8:29:47 PM UTC+10, mstep.germany wrote:
> > Search:
> >
> > \begin{center}
> > \textcolor{mygray}{\large w}
> > \end{center}
>
> To search for visually selected text, see http://vim.wikia.com/wiki/VimTip171
>
> I use the two vnoremap commands after "Search for selected text, forwards or backwards".
>
> John

Thank you John for your answer! I appreciate your answer even more, that you took the time for it in Easter Holidays. (<- sounds not like a good English idiom? Probably it's a French expression?).

Something I am doing wrong.

1. I put two lines in my .vimrc file:
a) vnoremap // y/<C-R>"<CR>
b) vnoremap <expr> // 'y/\V'.escape(@",'\').'<CR>'

I visual select the lines in my file to edit:


\begin{center}
\textcolor{mygray}{\large W}
\end{center}

I enter //

Result: /\V\\begin{center} in the status (command?) line. That means this is the first line from my visual selection only. Did I do something wrong?

What I need is the following:

I visual select the lines to search for, I hit a command (which one?), and in the status line I have my search pattern automatically with escaped special characters like follows:

:s/\\begin\{center\}\n \\textcolor\{mygray\}\{\\large W\}\n\\end\{center\}\n//

So that I can edit the search pattern in the status line like follows:

:%s/\\begin\{center\}(\s+)\\textcolor\{mygray\}\{\\large ([^}]+)\}\s+\\end\{center}\s+/$1\\vimcode{$2}\n/g

Would this be possible?

Best greetings to all


marek

--
--
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: