Loading ...
Sorry, an error occurred while loading the content.

Re: Preserving contents of a register in vimscript

Expand Messages
  • Nikolay Pavlov
    ... I know I can do ... LF, when it s restored it will be restored as a linewise selection, otherwise a characterwise one. ... select a chunk of text using
    Message 1 of 3 , Sep 12, 2013
    • 0 Attachment


      On Sep 12, 2013 1:01 PM, "Paul Moore" <p.f.moore@...> 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@....
      > 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@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Paul Moore
      ... Thanks, I hadn t spotted those functions. Paul -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text
      Message 2 of 3 , Sep 12, 2013
      • 0 Attachment
        On Thursday, 12 September 2013 10:08:57 UTC+1, ZyX wrote:
        > // 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.

        Thanks, I hadn't spotted those functions.
        Paul

        --
        --
        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@....
        For more options, visit https://groups.google.com/groups/opt_out.
      Your message has been successfully submitted and would be delivered to recipients shortly.