Monday, October 4, 2010

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

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@gmail.com> wrote:
On Fri, Oct 1, 2010 at 4:18 PM, sc <toothpik@swbell.net> 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

No comments: