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

How to copy text from vim to clipboard in Linux

Expand Messages
  • Alexander Dietz
    Hi, I am using vim on different, remote Linux systems, and what I would like to do is to copy some text in vim into the clipboard, so I can paste the text in
    Message 1 of 5 , Nov 3, 2010
    • 0 Attachment
      Hi,

      I am using vim on different, remote Linux systems, and what I would like to do is to copy some text in vim into the clipboard, so I can paste the text in some other application (i.e. xterm, email, emacs, openofice...). I do not have the possibility to recompile vim, as I would need to do that on several different machines I do not have root access.

      For example, I want to copy 3 lines from my vim session, so I can paste it into my email program by using either (i) the middle button of the mouse or (ii) by ordinary select 'paste' from the right-button mouse menu or the application's edit menu.

      I searched for doing so and got hints like using "+y after selecting the text or using "*y, but these suggestions do not work. I even put the line "set clipboard=unnamed" into my .vimrc without changing the behavior.

      Is there a way to do this WITHOUT the need for a recompilation? Or maybe I can put something useful into the .vimrc so something like that works? Or can I forget about this idea?


      Thanks
        Alex

      --
      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
    • Tim Chase
      ... It sounds like you re on the right track if you had a build of vim built with +clipboard You can check the output of :ver to see whether it was built
      Message 2 of 5 , Nov 3, 2010
      • 0 Attachment
        On 11/03/10 06:14, Alexander Dietz wrote:
        > I searched for doing so and got hints like using "+y after selecting the
        > text or using "*y, but these suggestions do not work. I even put the line
        > "set clipboard=unnamed" into my .vimrc without changing the behavior.

        It sounds like you're on the right track if you had a build of
        vim built with +clipboard You can check the output of ":ver" to
        see whether it was built with native clipboard support.

        The first thing I'd check is whether you have multiple builds of
        vim on your machine -- some distros include a "tiny" build of vim
        in the default install (often linked to "vi"), in addition to the
        huge build of vim/gvim with all the chocolate-toppings. If
        you're invoking the stripped-down version, a simple shell alias
        (or on Debian systems, the "update-alternatives" script) may get
        you the non-tiny build.

        If not, the only way I know of to get any clipboard functionality
        is to pipe your selection through xclip, which is usually
        available on most X systems and be able to read the man-pages
        (note that piping usually happens line-wise, so character-wise
        and block-wise visual-selections may have to be copied to a temp
        buffer, or make use of Dr. Chip's vis.vim plugin).

        :'<,'>!xclip -f

        (optionally tweaking the "-selection" parameter to xclip based on
        which clipboard you want...selection or clipboard)

        -tim



        --
        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
      • Alexander Dietz
        Hi, thanks for the reply ... I think the code has been compiled without clipboard support. I see only a -clipboard ... I have tried vim which gave the
        Message 3 of 5 , Nov 3, 2010
        • 0 Attachment
          Hi,

          thanks for the reply

          On Wed, Nov 3, 2010 at 14:09, Tim Chase <vim@...> wrote:
          On 11/03/10 06:14, Alexander Dietz wrote:
          I searched for doing so and got hints like using "+y after selecting the
          text or using "*y, but these suggestions do not work. I even put the line
          "set clipboard=unnamed" into my .vimrc without changing the behavior.

          It sounds like you're on the right track if you had a build of vim built with +clipboard   You can check the output of ":ver" to see whether it was built with native clipboard support.

          I think the code has been compiled without clipboard support. I see only a '-clipboard'
           

          The first thing I'd check is whether you have multiple builds of vim on your machine -- some distros include a "tiny" build of vim in the default install (often linked to "vi"), in addition to the huge build of vim/gvim with all the chocolate-toppings.  If you're invoking the stripped-down version, a simple shell alias (or on Debian systems, the "update-alternatives" script) may get you the non-tiny build.

          I have tried vim which gave the negative result as described above.
           

          If not, the only way I know of to get any clipboard functionality is to pipe your selection through xclip, which is usually available on most X systems and be able to read the man-pages (note that piping usually happens line-wise, so character-wise and block-wise visual-selections may have to be copied to a temp buffer, or make use of Dr. Chip's vis.vim plugin).

           :'<,'>!xclip -f


          xclip also does not seem to be installed on the different systems.
           
          (optionally tweaking the "-selection" parameter to xclip based on which clipboard you want...selection or clipboard)


          Any other idea I can try out, instead of quitting vi, doing a 'cat file', search for the place to copy, and manually copy with the mouse?



          Thanks
            Alex
           

          -tim




          --
          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
        • Tim Chase
          ... indeed ... If you have gvim (you ve already confirmed that vi and vim launch a -clipboard version of vim) you can launch it with the -v parameter
          Message 4 of 5 , Nov 3, 2010
          • 0 Attachment
            On 11/03/10 08:20, Alexander Dietz wrote:
            > I think the code has been compiled without clipboard support. I see only a
            > '-clipboard'

            indeed

            > I have tried vim which gave the negative result as described above.

            If you have gvim (you've already confirmed that "vi" and "vim"
            launch a "-clipboard" version of vim) you can launch it with the
            "-v" parameter (-v = "pretend you're vim, not gvim"), or try
            linking gvim to the name "vim" or "vi" earlier in your $PATH.

            If you really don't have an X-aware build of vim available at all
            (I'm sorry!), you'll have to rely on external mechanisms.

            > xclip also does not seem to be installed on the different systems.
            >
            > Any other idea I can try out, instead of quitting vi, doing a 'cat file',
            > search for the place to copy, and manually copy with the mouse?

            Well, you can limit the amount of output you have to wade through
            by writing just that excerpt to a file

            :'<,'>w temp_file.txt

            and then read it in with some other clipboard-aware program (or
            cat it to the screen, but then you're limited to the size of your
            terminal's scroll-back).

            Alternatively, if you have build-tools, Tony maintains a good
            "how to compile vim on Unix/Linux" page[1] and you could build
            Vim in your home directory (what I've done on several shared
            hosting services that only gave me vim-minimal).

            -tim


            [1]
            http://users.skynet.be/antoine.mechelynck/vim/compunix.htm
            further info at
            http://users.skynet.be/antoine.mechelynck/vim/index.htm

            --
            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
          • John Little
            On Nov 4, 12:14 am, Alexander Dietz wrote: By the way, ... In principle you do not need root access to compile vim for your
            Message 5 of 5 , Nov 3, 2010
            • 0 Attachment
              On Nov 4, 12:14 am, Alexander Dietz <alexanderdie...@...>
              wrote:

              By the way,

              > I do not
              > have the possibility to recompile vim, as I would need to do that on several
              > different machines I do not have root access.

              In principle you do not need root access to compile vim for your own
              use. It's easy even, unless some of the libraries and headers you
              need are missing, in which case it gets messy, but still doable.

              Regards, John

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