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

Re: Custom whitespace handling for cut and paste

Expand Messages
  • Ben Fritz
    ... This exists with the as text object. For example: Sentence one. Sentence two. Sentence three. Sentence four. Sentence five. Sentence six. Place the
    Message 1 of 6 , Nov 27, 2012
    • 0 Attachment
      On Tuesday, November 27, 2012 9:40:33 AM UTC-6, coot_. wrote:
      >
      >
      >
      > Yes and no. You can make a sentence text object which will add the
      >
      > missing spaces to the yanked text

      This exists with the "as" text object.

      For example:

      Sentence one. Sentence two. Sentence three.
      Sentence four. Sentence five. Sentence six.

      Place the cursor anywhere on "Sentence two." Type the three keys,
      "das". Place the cursor on the space between "Sentence four." and "Sentence five." Press p to paste. Get:

      Sentence one. Sentence three.
      Sentence four. Sentence two. Sentence five. Sentence six.

      It doesn't do the smart rebalancing of spaces on the paste; perhaps you could add that with a mapping. But the cut/copy is easy.

      --
      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
    • Andy Wokula
      ... I ve created smartput.vim for this purpose. It adjusts spaces when text is pasted (or `put in vimspeak) (rather than when text is deleted). That works
      Message 2 of 6 , Nov 27, 2012
      • 0 Attachment
        Am 27.11.2012 15:26, schrieb KamilS:
        > I primarily use Vim for LaTeX, i.e. for editing text rather than code,
        > and I was wondering if it's possible to make Vim handle whitespace in
        > a smarter way when cutting and pasting in in .tex files.
        >
        > In particular, I would like to see the kind of behaviour I know and
        > love from Adobe InDesign. Let me give you an example:
        >
        > Sentence one. Sentence two. Sentence three.
        >
        > Now, if I select "Sentence two." (just this much, without the
        > surrounding spaces) and cut it, InDesign will automatically delete one
        > of the two remaining subsequent spaces. If I then paste it between
        > "Sentence" and "three", never mind on which side of the space between
        > them, InDesign will automatically add the missing space before or
        > after it.
        >
        > The same happens with single words. Which makes sense because when you
        > write text, you want to cut and paste words most of the time, not just
        > bits of words.
        >
        > Is it possible to implement this kind of behaviour in Vim and limit it
        > to .tex files? Or is there perhaps a plugin for it already, only I
        > couldn't find it?

        I've created smartput.vim for this purpose. It adjusts spaces when text
        is pasted (or `put' in vimspeak) (rather than when text is deleted).

        That works fine with Vim's sentence text objects
        :h as
        :h is
        and motions
        :h (
        :h )
        which (when deleting text) either let you decide how much whitespace to
        include (`is' vs. `as') or include the whitespace after a sentence
        (`)').

        When putting a word between other words (or in the middle of a word),
        smartput inserts spaces around the inserted word.

        Smartput is a global plugin, you can enable/disable it globally (by a
        key `<Leader>st') or turn it off for a filetype where it is unwanted
        (this is a little different from what you want).

        There are rules (global or buffer-local variables) to adjust when to
        insert/remove a space ... yet this system is not as flexible (and user
        friendly ^^) as it could be.

        Yep, smartput.vim is quite old (omg, last update 2007-12-16, sorry), but
        it should do what you want. I use it myself all the time (a modified,
        half-way-ready unreleased version though).

        --
        Andy

        --
        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
      • Andy Wokula
        Smartput http://vim.sourceforge.net/scripts/script.php?script_id=2095 -- Andy -- You received this message from the vim_use maillist. Do not top-post! Type
        Message 3 of 6 , Nov 27, 2012
        • 0 Attachment
          Smartput
          http://vim.sourceforge.net/scripts/script.php?script_id=2095

          --
          Andy

          --
          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
        • KamilS
          Thanks for all the answers! I guess I will need a little time to try each in practice and see which one I feel most comfortable with. At any rate, it s great
          Message 4 of 6 , Nov 27, 2012
          • 0 Attachment
            Thanks for all the answers! I guess I will need a little time to try each in practice and see which one I feel most comfortable with. At any rate, it's great to know that Vim can do this, too.

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