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

How to configure vim to use the mouse, AND to copy and paste

Expand Messages
  • Alexander Dietz
    Hi, I have questions regarding vim and how to enable the mouse in it. There were some other threads about that issue, but I could not find a solution for my
    Message 1 of 8 , Sep 30, 2010
    • 0 Attachment
      Hi,

      I have questions regarding vim and how to enable the mouse in it. There were some other threads about that issue, but I could not find a solution for my problem.

      I would like to have the following actions enabled in vim:

      1. To go to some place, I click the left mouse key
      2. To copy text TO the vim editor by using the middle-click of the mouse, (text which I have marked before in some other window (browser, emacs, xterm))
      3. To copy text FROM the vim editor, by selecting the text with the left mouse button (left-click, hold down, select text, release left button), so I can paste it to somwehere else with the mouse middle button
      4. To copy text and paste TO and FROM vim 

      I have the following content of my .vimrc:

      :set mouse=r
      :set selectmode+=mouse

      With that configuration, the points 2-4 are working.
      When I change mouse=r to mouse=a, then points 1 AND 3 are working, but I have to press the shift key in addition. But I cannot use the mouse to go somewhere else in vim.

      A suggestion was to use mouse=ar, but this enable only the first point.

      So how is it possible to configure vim to use all four points 1-4?


      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
    • Ven Tadipatri
      Well, this doesn t answer the question I asked earlier about using visual mode to copy and paste. But if you use xclip to copy, and ctrl+shift+v to paste, then
      Message 2 of 8 , Sep 30, 2010
      • 0 Attachment
        Well, this doesn't answer the question I asked earlier about using
        visual mode to copy and paste.
        But if you use xclip to copy, and ctrl+shift+v to paste, then setting
        mouse=a, you can get all the functionality you want. It does take some
        getting used to probably, since you can't use the middle mouse button
        to paste.
        If you can find a way to copy that's not as messy as putting this
        in your .vimrc, please let me know:
        vmap <C-c> :<Esc>`>a<CR><Esc>mx`<i<CR><Esc>my'xk$v'y!xclip -selection c<CR>u

        Thanks,
        Ven

        On Thu, Sep 30, 2010 at 9:59 AM, Alexander Dietz
        <alexanderdietz1@...> wrote:
        > Hi,
        >
        > I have questions regarding vim and how to enable the mouse in it. There were
        > some other threads about that issue, but I could not find a solution for my
        > problem.
        >
        > I would like to have the following actions enabled in vim:
        >
        > 1. To go to some place, I click the left mouse key
        > 2. To copy text TO the vim editor by using the middle-click of the mouse,
        > (text which I have marked before in some other window (browser, emacs,
        > xterm))
        > 3. To copy text FROM the vim editor, by selecting the text with the left
        > mouse button (left-click, hold down, select text, release left button), so I
        > can paste it to somwehere else with the mouse middle button
        > 4. To copy text and paste TO and FROM vim
        >
        > I have the following content of my .vimrc:
        >
        > :set mouse=r
        > :set selectmode+=mouse
        >
        > With that configuration, the points 2-4 are working.
        > When I change mouse=r to mouse=a, then points 1 AND 3 are working, but I
        > have to press the shift key in addition. But I cannot use the mouse to go
        > somewhere else in vim.
        >
        > A suggestion was to use mouse=ar, but this enable only the first point.
        >
        > So how is it possible to configure vim to use all four points 1-4?
        >
        >
        > 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
        >

        --
        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, first of all thanks for a reply, although it does not answer all of my question. ... (what is xclip???) ... If you can find a way to copy that s not as
        Message 3 of 8 , Sep 30, 2010
        • 0 Attachment
          Hi,

          first of all thanks for a reply, although it does not answer all of my question.


          On Thu, Sep 30, 2010 at 18:05, Ven Tadipatri <vtadipatri@...> wrote:
          Well, this doesn't answer the question I asked earlier about using
          visual mode to copy and paste.
          But if you use xclip to copy,

          (what is xclip???)
           
          and ctrl+shift+v to paste, then setting
          mouse=a, you can get all the functionality you want. It does take some
          getting used to probably, since you can't use the middle mouse button
          to paste.
            If you can find a way to copy that's not as messy as putting this
          in your .vimrc, please let me know:
          vmap <C-c> :<Esc>`>a<CR><Esc>mx`<i<CR><Esc>my'xk$v'y!xclip -selection c<CR>u
           
           
          with this unreadable mix of letters and characters, I am now able to use functionalities 1 and 2 of my have-to list (with having the shift key to press in addition). I still cannot paste text, which I have marked with the mouse, to vim or a different editor.

          Maybe there is still a way to configure vim in the right way? Are no vim specialists on this list?


          Thanks
            Alex


          Thanks,
          Ven

          On Thu, Sep 30, 2010 at 9:59 AM, Alexander Dietz
          <alexanderdietz1@...> wrote:
          > Hi,
          >
          > I have questions regarding vim and how to enable the mouse in it. There were
          > some other threads about that issue, but I could not find a solution for my
          > problem.
          >
          > I would like to have the following actions enabled in vim:
          >
          > 1. To go to some place, I click the left mouse key
          > 2. To copy text TO the vim editor by using the middle-click of the mouse,
          > (text which I have marked before in some other window (browser, emacs,
          > xterm))
          > 3. To copy text FROM the vim editor, by selecting the text with the left
          > mouse button (left-click, hold down, select text, release left button), so I
          > can paste it to somwehere else with the mouse middle button
          > 4. To copy text and paste TO and FROM vim
          >
          > I have the following content of my .vimrc:
          >
          > :set mouse=r
          > :set selectmode+=mouse
          >
          > With that configuration, the points 2-4 are working.
          > When I change mouse=r to mouse=a, then points 1 AND 3 are working, but I
          > have to press the shift key in addition. But I cannot use the mouse to go
          > somewhere else in vim.
          >
          > A suggestion was to use mouse=ar, but this enable only the first point.
          >
          > So how is it possible to configure vim to use all four points 1-4?
          >
          >
          > 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
          >

          --
          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 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
        • Ven Tadipatri
          On Thu, Sep 30, 2010 at 2:57 PM, Alexander Dietz ... xclip is a utility that allows you to use the clipboard on Linux machines that use X11:
          Message 4 of 8 , Oct 1, 2010
          • 0 Attachment
            On Thu, Sep 30, 2010 at 2:57 PM, Alexander Dietz
            <Alexander.Dietz72@...> wrote:
            > Hi,
            >
            > first of all thanks for a reply, although it does not answer all of my
            > question.
            >
            >
            > On Thu, Sep 30, 2010 at 18:05, Ven Tadipatri <vtadipatri@...> wrote:
            >>
            >> Well, this doesn't answer the question I asked earlier about using
            >> visual mode to copy and paste.
            >> But if you use xclip to copy,
            >
            > (what is xclip???)

            xclip is a utility that allows you to use the clipboard on Linux
            machines that use X11:
            http://sourceforge.net/projects/xclip/

            Copy and paste is such a basic functionality, and I'm really surprised
            that vim doesn't have a nice platform-independent way of handling
            this. Actually even a platform-dependent way of copying and pasting
            would work - it would just be nice if this were better documented
            somewhere.

            >>
            >>   If you can find a way to copy that's not as messy as putting this
            >> in your .vimrc, please let me know:
            >> vmap <C-c> :<Esc>`>a<CR><Esc>mx`<i<CR><Esc>my'xk$v'y!xclip -selection
            >> c<CR>u
            >>

            That was something I figured out the painful way. What I basically do
            is take the text to copy, put it on its own line, mark the beginning
            of it, mark the end of it, and send it to xclip, which sends it to the
            clipboard. But now, since the command executed, it wiped out the text
            you wanted to copy, so I put a u at the end to undo it. If there's a
            hall of fame for vim hacks, this should definitely go on it!

            >
            >
            > with this unreadable mix of letters and characters, I am now able to use
            > functionalities 1 and 2 of my have-to list (with having the shift key to

            Wait, so then you must have xclip on your machine, if you got it to work, right?

            > press in addition). I still cannot paste text, which I have marked with the
            > mouse, to vim or a different editor.
            >
            > Maybe there is still a way to configure vim in the right way? Are no vim
            > specialists on this list?

            I'm working on the paste part myself, but I'm having difficulties getting my
            ctrl+shift+v to work (it works on Linux, but not in Cygwin). I played
            around a bit with the inputrc and now when I want to paste, it puts me
            into visual mode - great.
            Pardon my sarcasm, but yes, it bothers me a bit when we need to ask
            a "vim specialist" on how to get copy and paste working. It should
            definitely not be this complicated. I wonder, how do all the vim users
            on this list use copy and paste?

            Thanks,
            Ven

            >
            >
            > Thanks
            >   Alex
            >
            >
            >> Thanks,
            >> Ven
            >>

            --
            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
          • Erik Falor
            ... xclip lets you access the X11 clipboard on the command-line. In other words, you can pipe text to and from the X11 selection buffer. -- Erik Falor
            Message 5 of 8 , Oct 1, 2010
            • 0 Attachment
              On Fri, Oct 01, 2010 at 03:44:31PM -0400, Ven Tadipatri wrote:
              > On Thu, Sep 30, 2010 at 2:57 PM, Alexander Dietz
              > <Alexander.Dietz72@...> wrote:
              > > Hi,
              > >
              > > first of all thanks for a reply, although it does not answer all of my
              > > question.
              > >
              > >
              > > On Thu, Sep 30, 2010 at 18:05, Ven Tadipatri <vtadipatri@...> wrote:
              > >>
              > >> Well, this doesn't answer the question I asked earlier about using
              > >> visual mode to copy and paste.
              > >> But if you use xclip to copy,
              > >
              > > (what is xclip???)
              >
              > xclip is a utility that allows you to use the clipboard on Linux
              > machines that use X11:
              > http://sourceforge.net/projects/xclip/

              xclip lets you access the X11 clipboard on the command-line. In other
              words, you can pipe text to and from the X11 selection buffer.

              --
              Erik Falor
              Registered Linux User #445632 http://counter.li.org
            • sc
              ... speaking for myself only, i got used to using ctrl-insert and shift-insert way back in my windows days because they worked in more places than ctrl-c and
              Message 6 of 8 , Oct 1, 2010
              • 0 Attachment
                On Friday 01 October 2010 14:44:31 Ven Tadipatri wrote:

                > definitely not be this complicated. I wonder, how do all the
                > vim users on this list use copy and paste?

                speaking for myself only, i got used to using ctrl-insert and
                shift-insert way back in my windows days because they worked
                in more places than ctrl-c and ctrl-v

                i have several lines relating to them in my .vimrc:

                nmap <S-Insert> "+gP
                vmap <S-Insert> "-d"+P
                imap <S-Insert> <C-O>:set paste<CR><C-R>+\|<C-O>:set nopaste<CR>
                cmap <S-Insert> <C-R>+
                imap <C-Insert> <C-O>"+y
                vmap <C-Insert> "+y
                vmap <S-Del> "+d
                imap <C-Del> <C-O>daw

                and lately, if i want to quit an app i am copying from before
                i paste i make sure and start klipper beforehand

                sc

                --
                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
              • Ven Tadipatri
                ... Unfortunately I haven t come across a system yet where the + buffers were enabled. That s why I had to jump through all these hoops with /dev/clipboard
                Message 7 of 8 , Oct 1, 2010
                • 0 Attachment
                  On Fri, Oct 1, 2010 at 4:18 PM, sc <toothpik@...> wrote:
                  > On Friday 01 October 2010 14:44:31 Ven Tadipatri wrote:
                  >
                  >
                  > i have several lines relating to them in my .vimrc:
                  >
                  > nmap <S-Insert> "+gP
                  > vmap <S-Insert> "-d"+P
                  > imap <S-Insert> <C-O>:set paste<CR><C-R>+\|<C-O>:set nopaste<CR>
                  > cmap <S-Insert> <C-R>+
                  > imap <C-Insert> <C-O>"+y
                  > vmap <C-Insert> "+y
                  > vmap <S-Del> "+d
                  > imap <C-Del> <C-O>daw

                  Unfortunately I haven't come across a system yet where the + buffers
                  were enabled. That's why I had to jump through all these hoops with
                  /dev/clipboard with Cygwin, and xclip on the Linux machines that used
                  X11.

                  So here's the latest attempt at pasting:

                  For Cygwin:
                  nmap <C-v> iz<Esc>mz:execute "normal a".system("cat /dev/clipboard")[:-2]<CR>`zx

                  For Linux:
                  nmap <C-v> iz<Esc>mz:execute "normal a".system("xclip -o")[:-2]<CR>`zx

                  or map it to the Middle Mouse:
                  map <MiddleMouse> iz<Esc>mz:execute "normal a".system("xclip -o")[:-2]<CR>`zx


                  Apparently when I execute a command, it puts it on the next line, but
                  this "normal a".system, passing it a system command pasted it right
                  where I want. Well, almost, because if I pasted it at the beginning
                  of the line, it pasted *after* the first character, which was
                  annoying. So I did another hack using marks to paste.

                  Ctrl+insert is a good idea if you don't want to overwrite the ctrl+v,
                  which is used to print out an escape character. That's why I was made
                  the key mappings for normal mode only, not visual or command mode.

                  Thanks,
                  Ven

                  >
                  > and lately, if i want to quit an app i am copying from before
                  > i paste i make sure and start klipper beforehand
                  >
                  > sc
                  >

                  --
                  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, I am not sure if I correctly understood these tips. There were some ideas of using crtl+v and crtl+insert for copy/pasting text, but this is not what I
                  Message 8 of 8 , Oct 4, 2010
                  • 0 Attachment
                    Hi,

                    I am not sure if I correctly understood these tips. There were some ideas of using crtl+v and crtl+insert for copy/pasting text, but this is not what I want.

                    I want to copy a text to the clipboard by just marking the text in vim, and the using the middle-button of the mouse to paste it into my vim session (currently, I can paste text from the clipboard from somewhere else using shift-middle-button, which is just quite ok). I tried the tips given here (i.e. the long list of xmap instructions and the following:
                    map <MiddleMouse> iz<Esc>mz:execute "normal a".system("xclip -o")[:-2]<CR>`zx)

                    but still I cannot paste text in vim which I have selected before in vim. I have the following .vimrc:

                    :set number
                    :set paste
                    :set mouse=a

                    autocmd FileType * set tabstop=2|set shiftwidth=2|set noexpandtab
                    autocmd FileType python set tabstop=4|set shiftwidth=4|set expandtab
                    autocmd BufEnter * set ai sw=4 ts=4 sta et fo=croql
                    set softtabstop=4 " makes the spaces feel like real tabs

                    The following is a list of items that work, and which I want to work later as well:
                    1. I can use the mouse to left-click, to put the cursor to another place
                    2. I can paste text in (by using shift - middle-mouse-button) from some other application

                    But the following items do NOT work:
                    A. I cannot mark text in vim to copy it to the clipboard. I cannot paste text from vim to vim or some other application.

                    So my question: Is it possible to configure vim in that way so that marking as text will put it into the clipboard (so that a subsequent middle-click of the mouse will paste it to somewhere else) WITHOUT loosing the first two currently working abilities...? Is that possible at all without having to install something different (which I had to do on ~10 other computers as non-root...).

                    I hope it is clear this time. Sorry if I was not very clear before.


                    Thanks
                      Alex



                    On Fri, Oct 1, 2010 at 22:48, Ven Tadipatri <vtadipatri@...> wrote:
                    On Fri, Oct 1, 2010 at 4:18 PM, sc <toothpik@...> wrote:
                    > On Friday 01 October 2010 14:44:31 Ven Tadipatri wrote:
                    >
                    >
                    > i have several lines relating to them in my .vimrc:
                    >
                    > nmap <S-Insert> "+gP
                    > vmap <S-Insert> "-d"+P
                    > imap <S-Insert> <C-O>:set paste<CR><C-R>+\|<C-O>:set nopaste<CR>
                    > cmap <S-Insert> <C-R>+
                    > imap <C-Insert> <C-O>"+y
                    > vmap <C-Insert> "+y
                    > vmap <S-Del> "+d
                    > imap <C-Del> <C-O>daw

                    Unfortunately I haven't come across a system yet where the + buffers
                    were enabled. That's why I had to jump through all these hoops with
                    /dev/clipboard with Cygwin, and xclip on the Linux machines that used
                    X11.

                    So here's the latest attempt at pasting:

                    For Cygwin:
                    nmap <C-v> iz<Esc>mz:execute "normal a".system("cat /dev/clipboard")[:-2]<CR>`zx

                    For Linux:
                    nmap <C-v> iz<Esc>mz:execute "normal a".system("xclip -o")[:-2]<CR>`zx

                    or map it to the Middle Mouse:
                    map <MiddleMouse> iz<Esc>mz:execute "normal a".system("xclip -o")[:-2]<CR>`zx


                    Apparently when I execute a command, it puts it on the next line, but
                    this "normal a".system, passing it a system command pasted it right
                    where I want.  Well, almost, because if I pasted it at the beginning
                    of the line, it pasted *after* the first character, which was
                    annoying. So I did another hack using marks to paste.

                    Ctrl+insert is a good idea if you don't want to overwrite the ctrl+v,
                    which is used to print out an escape character. That's why I was made
                    the key mappings for normal mode only, not visual or command mode.

                    Thanks,
                    Ven

                    >
                    > and lately, if i want to quit an app i am copying from before
                    > i paste i make sure and start klipper beforehand
                    >
                    > sc
                    >

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