Thursday, September 12, 2013

Re: Preserving contents of a register in vimscript


On Sep 12, 2013 1:01 PM, "Paul Moore" <p.f.moore@gmail.com> wrote:
>
> Is it possible to preserve a register in vimscript while I do some work? I know I can do
>
>     :let saved_a = @a
>     ...
>     : let @a = saved_a
>
> to preserve the text in the register. And if that text ends with a CR or LF, when it's restored it will be restored as a linewise selection, otherwise a characterwise one.
>
> But is it possible to preserve content that is blockwise? Suppose I select a chunk of text using Ctrl-V and then do "ay. If I do the above, then paste, it will be pasted characterwise rather than blockwise.
>
> I'm trying to write a script that uses a couple of registers, and I want to avoid trashing them. I could just say register z (say) is reserved for my script, but I'd rather not do that if I can avoid it...
>
> Thanks,
> Paul

// Use getreg()+getregtype() and setreg() with three arguments.

What you are trying to achieve is not possible without pasting to some temporary buffer and reading with getline() then (when restoring) pasting again (with setline()) and using normal-mode y command. Just try to yank NUL (obtained by e.g. :call setline('.', "a\nb")) and restore it.

> --
> --
> 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/groups/opt_out.

--
--
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/groups/opt_out.

No comments: