Re: problem: redirection of global print to register
Hi, Nick Shyrokovskiy wrote: Say initially I have a buffer: --buffer-- a1 a2 - if i sequentially issue: :redir @c :g/a./ :redir END :put c I'll get and i'll see 2 matched lines in vim output as :g is not silent --buffer-- a1 a2 a1 a2 -- but if issue: :redir @c | g/a./ | redir END :put c I'll see somewhat different vim output but again 2 matched lines, but the buffer will be --buffer-- a1 a2 a1 -- the :global command takes all following commands and executes them for all matching lines. So what you are seeing here is that :global marks both for further processing and then prints the first line and stops redirection, then prints the second line and again stops (the already stopped) redirection. Effectively you are telling Vim to only capture the first line that matches the pattern after :global. Once again if I issue: :redir @c | g/a./ | redir END | put c that's what I'll get in buffer, output is OK again --buffer-- a1 a1 a2 a1 -- No, the output is not what you expected. Vim only captures the first line and puts it into the buffer twice. Regards, Jürgen -- Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us. (Calvin) -- 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
Re: problem: redirection of global print to register
On Fri, June 15, 2012 09:57, Nick Shyrokovskiy wrote: On Friday, June 15, 2012 8:32:44 AM UTC+3, Christian Brabandt wrote: Do you mean, you see something different, than what is redirected? I can't reproduce this. I'll give an example. Say initially I have a buffer: --buffer-- a1 a2 - if i sequentially issue: :redir @c :g/a./ :redir END :put c I'll get and i'll see 2 matched lines in vim output as :g is not silent --buffer-- a1 a2 a1 a2 -- but if issue: :redir @c | g/a./ | redir END :put c I'll see somewhat different vim output but again 2 matched lines, but the buffer will be --buffer-- a1 a2 a1 -- Once again if I issue: :redir @c | g/a./ | redir END | put c that's what I'll get in buffer, output is OK again --buffer-- a1 a1 a2 a1 Your problem is, the :redir END part is seen as argument to the :g command, that is, for each matching line, the :redir END command is issued and therefore you only get the first match in your register. To prevent this, you can use :exe if you want to put this in one single line, e.g. :redir @c|exe g/a./|redir END See :h :bar :h :exe regards, Christian -- 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
Re: problem: redirection of global print to register
Thank you for explanation and suggestion. I really need to :h :bar -- 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
Re: problem: redirection of global print to register
On Friday, June 15, 2012 11:23:58 AM UTC+3, Christian Brabandt wrote: To prevent this, you can use :exe if you want to put this in one single line, e.g. :redir @c|exe g/a./|redir END I've learned a better way to make it one line from help: :redir @c | g/a./^@redir END where ^@ is one character, it's newline and it's inserted with C-V C-J -- 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
Re: problem: redirection of global print to register
On Friday, June 15, 2012 5:00:27 AM UTC-5, Nick Shyrokovskiy wrote: On Friday, June 15, 2012 11:23:58 AM UTC+3, Christian Brabandt wrote: To prevent this, you can use :exe if you want to put this in one single line, e.g. :redir @c|exe g/a./|redir END I've learned a better way to make it one line from help: :redir @c | g/a./^@redir END where ^@ is one character, it's newline and it's inserted with C-V C-J How on Earth is that better? This is one of the most common uses of the :exe command, and much easier to see what's going on than needing to puzzle out what the unprintable character is doing on the command-line. -- 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