Tuesday, May 24, 2016

Re: Use Register as Search Pattern in Ex Mode silent

On Monday, May 23, 2016 at 4:44:35 AM UTC-5, Marcel Jödicke wrote:
>
> Hello Ben,
>
> Thank you very much for your answer!
>
> I looked into :execute, but I'm not really understand the way to use it. For example, I have now found a way to do that with let. I open my 3 files in seperate tabs with the -p parameter, copy my replacement pattern with let @@=getline('.'), copy my search pattern with @/=getline('.') and search and replace in the main File with :%s//\=@@/g how would I make such command with exec? Sadly the let command doesn't seem to work silent, else my problem would be solved...
>


What do you mean by, "the let command doesn't seem to work silent"? You can certainly invoke :let commands in a user mapping, commands from the shell, or wherever you need.

I'm confused what you're trying to do, actually.

Your original question was how to use a register as a search pattern from a command-line (not interactive). For a substitute command, that would be something like:

:execute 's/'.@a.'/replacement/'

Note how the :execute command takes a string, which you can build using a register content. Here, I used register @a.

You could also use the unnamed register @@, the copy register @0, the delete registers @1-@9, and more. The system clipboard is @+ or @*.

Your example you give uses "let" to set the content of the unnamed register. You could do this with just a yank command.

You said you had trouble using the "let" command silently, but I don't know what that means. Something like :let @/=getline('.') should work just fine.

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

Post a Comment