Search & replace with grep

6 messages
Open this post in threaded view
|

Search & replace with grep

 Hello all! I switched from Mac BBEdit to vim and need help with a grep pattern. I am still a beginner and putting up a VIM cheat file in LATEX for all vim-commands, which are part of my "repertoire". My search pattern is following, and there are many of them in my file: Search: \begin{center}   \textcolor{mygray}{\large w} \end{center} Replace:    \vimcode{w} My try was the following: :s/\begin{center}\n$$\s\+$$\textcolor{mygray}{\large $$[^}]\+$$}\s+\end{center}\s+/$1\vimcode{$2}/g Do I have to escape all \begin with \\begin ? This would be cumbersome and a reason to give up VIM. Already to escape the capturing parenthesis  you have to get used to. Is there a possibility to visual select some lines, to edit them in the search dialogue? Would it be possible, to put visual  selected lines into the search dialogue with all special signs escaped automatically? Thank you in advance 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 [hidden email]. For more options, visit https://groups.google.com/d/optout.
Open this post in threaded view
|

Re: Search & replace with grep

 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/VimTip171I use the two vnoremap commands after "Search for selected text, forwards or backwards". 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 [hidden email]. For more options, visit https://groups.google.com/d/optout.
Open this post in threaded view
|

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/"     b) vnoremap // 'y/\V'.escape(@",'\').'' 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 [hidden email]. For more options, visit https://groups.google.com/d/optout.
Open this post in threaded view
|

Re: Search & replace with grep

 In reply to this post by mstep.germany On Sunday, 1 April 2018 12:29:47 UTC+2, [hidden email]  wrote: Sorry I forgot to escape the capturing  So my search pattern should be: :s/\begin{center}\n$$\s\+$$\textcolor{mygray}{\large $$[^}]\+$$}\s+\end{center}\s+/$1\vimcode{$2}/g -- -- 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 [hidden email]. For more options, visit https://groups.google.com/d/optout.