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

How to do a relative paste?

Expand Messages
  • AK
    Hi, how can I paste keeping both the original indent and the indent of pasted text, but not increasing with each line? In other words, let s say I have this
    Message 1 of 5 , Apr 10, 2012
    • 0 Attachment
      Hi, how can I paste keeping both the original indent and the indent
      of pasted text, but not increasing with each line?

      In other words, let's say I have this text:

      #slide {
      top: 10px;
      }

      I want to paste it to a location that looks like this:

      <style>
      li { float: left }
      |
      </style>

      | indicates where it should be pasted. It should end up looking like:

      <style>
      li { float: left }
      #slide {
      top: 10px;
      }
      </style>

      It seems like a pretty reasonable default paste behaviour, doesn't it?

      -ak

      --
      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
    • Benjamin R. Haskell
      ... It sounds like you want ]p See: :help ]p ... Depends. Sometimes you don t necessarily want it indented to the same level. -- Best, Ben -- You received
      Message 2 of 5 , Apr 10, 2012
      • 0 Attachment
        On Tue, 10 Apr 2012, AK wrote:

        > Hi, how can I paste keeping both the original indent and the indent of
        > pasted text, but not increasing with each line?

        It sounds like you want ]p

        See: :help ]p

        > In other words, let's say I have this text:
        >
        > #slide {
        > top: 10px;
        > }
        >
        > I want to paste it to a location that looks like this:
        >
        > <style>
        > li { float: left }
        > |
        > </style>
        >
        > | indicates where it should be pasted. It should end up looking like:
        >
        > <style>
        > li { float: left }
        > #slide {
        > top: 10px;
        > }
        > </style>
        >
        > It seems like a pretty reasonable default paste behaviour, doesn't it?

        Depends. Sometimes you don't necessarily want it indented to the same
        level.

        --
        Best,
        Ben

        --
        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
      • AK
        ... That doesn t work for me when pasting from * register. Here s what I end up with: #ribbon { position:absolute; top:-3px; left:-15px; z-index:500; } when
        Message 3 of 5 , Apr 10, 2012
        • 0 Attachment
          On 04/10/2012 06:22 PM, Benjamin R. Haskell wrote:
          > On Tue, 10 Apr 2012, AK wrote:
          >
          >> Hi, how can I paste keeping both the original indent and the indent of
          >> pasted text, but not increasing with each line?
          >
          > It sounds like you want ]p
          >
          > See: :help ]p


          That doesn't work for me when pasting from * register. Here's what I end
          up with:

          #ribbon {
          position:absolute;
          top:-3px;
          left:-15px;
          z-index:500;
          }

          when desired output is:

          #ribbon {
          position:absolute;
          top:-3px;
          left:-15px;
          z-index:500;
          }

          -ak

          --
          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
        • Alejandro Exojo
          ... Unfortunately, this kind of stuff depends a lot on a good indent file. Still, I think the best way to do it is not with maps that adjust indentation, since
          Message 4 of 5 , Apr 10, 2012
          • 0 Attachment
            El Miércoles, 11 de abril de 2012, AK escribió:
            > On 04/10/2012 06:22 PM, Benjamin R. Haskell wrote:
            > > On Tue, 10 Apr 2012, AK wrote:
            > >> Hi, how can I paste keeping both the original indent and the indent of
            > >> pasted text, but not increasing with each line?
            > >
            > > It sounds like you want ]p
            > >
            > > See: :help ]p
            >
            > That doesn't work for me when pasting from * register. Here's what I end
            > up with:
            >
            > #ribbon {
            > position:absolute;
            > top:-3px;
            > left:-15px;
            > z-index:500;
            > }
            >
            > when desired output is:
            >
            > #ribbon {
            > position:absolute;
            > top:-3px;
            > left:-15px;
            > z-index:500;
            > }

            Unfortunately, this kind of stuff depends a lot on a good indent file. Still, I
            think the best way to do it is not with maps that adjust indentation, since
            that might break the previous indentation of whatever you are pasting.

            The best solution I have found so far is the one implemented with this plugin:
            https://github.com/sickill/vim-pasta.git

            It does a very simple but smart thing: before pasting, adds a line with o/O
            that later is deleted.

            I found it works much better than I initially expected. And if you are like
            me, you would still want a map that selects what you just pasted, so you can
            fine tune if needed:

            nnoremap <expr> <leader>m "`[" . strpart(getregtype(), 0, 1) . "`]"

            Greetings.

            --
            Alex (a.k.a. suy) | GPG ID 0x0B8B0BC2
            http://barnacity.net/ | http://disperso.net

            --
            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
          • Benjamin R. Haskell
            ... What kind of file are you editing? That works fine for me in all of: - HTML (within a element) - PHP (within a element) - CSS (anywhere)
            Message 5 of 5 , Apr 14, 2012
            • 0 Attachment
              On Tue, 10 Apr 2012, AK wrote:

              > On 04/10/2012 06:22 PM, Benjamin R. Haskell wrote:
              >> On Tue, 10 Apr 2012, AK wrote:
              >>
              >>> Hi, how can I paste keeping both the original indent and the indent
              >>> of pasted text, but not increasing with each line?
              >>
              >> It sounds like you want ]p
              >>
              >> See: :help ]p
              >
              >
              > That doesn't work for me when pasting from * register. Here's what I
              > end up with:
              >
              > #ribbon {
              > position:absolute;
              > top:-3px;
              > left:-15px;
              > z-index:500;
              > }
              >
              > when desired output is:
              >
              > #ribbon {
              > position:absolute;
              > top:-3px;
              > left:-15px;
              > z-index:500;
              > }

              What kind of file are you editing? That works fine for me in all
              of:
              - HTML (within a <style> element)
              - PHP (within a <style> element)
              - CSS (anywhere)

              What do you mean by "pasting from * register"? It didn't behave any
              differently for me regardless of what register I used.

              Is the source content properly indented? ]p won't fix the indentation,
              except to modify it the same way the first line needs to be modified to
              be properly indented in context.

              So, e.g., if you paste (with ]p), the following:

              #blah {
              width: 100%;
              height: 100%; /* too much indent */
              }

              After:
              #something {
              width: 100%;
              }

              You'll end up with:
              #something {
              width: 100%;
              }
              #blah {
              width: 100%;
              height: 100%; /* (still) too much indent */
              }

              Similarly, pasting:

              #blah { /* already indented */
              width: 100%;
              height: 100%; /* too much indent */
              }

              After:

              #something {
              width: 100%;
              }

              Yields:

              #something {
              width: 100%;
              }
              #blah {
              width: 100%;
              height: 100%; /* (still) too much indent */
              }

              --
              Best,
              Ben

              --
              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
            Your message has been successfully submitted and would be delivered to recipients shortly.