[arch-general] Vim with X

Bastien Dejean nihilhill at gmail.com
Thu Nov 17 15:08:01 EST 2011


Manolo Martínez a écrit :

> As it is now, the standalone vim cannot copy to and from the X clipboard.

I wrote the following functions to circumvent the problem:

    function! Yank(...)
        if a:0
            let response = system("xsel -pi", a:1)
        else
            let response = system("xsel -pi", @")
        endif
    endfunction

    function! YankClip(...)
        if a:0
            let response = system("xsel -bi", a:1)
        else
            let response = system("xsel -bi", @")
        endif
    endfunction

    function! Paste(paste_before, use_primary)
        let at_q = @q
        if a:use_primary
            let @q = system("xsel -po")
        else
            let @q = system("xsel -bo")
        endif
        if a:paste_before
            normal! "qP
        else
            normal! "qp
        endif
        let @q = at_q
    endfunction

Here's the bindings I use:

    vmap <silent> <leader>y y:call Yank()<cr>
    vmap <silent> <leader>gy y:call YankClip()<cr>
    nmap <silent> <leader>yy yy:call Yank()<cr>
    nmap <silent> <leader>p :call Paste(0, 1)<cr>
    nmap <silent> <leader>P :call Paste(1, 1)<cr>
    nmap <silent> <leader>gp :call Paste(1, 0)<cr>
    nmap <silent> <leader>gP :call Paste(1, 0)<cr>

Greetings,
-- 
Bastien


More information about the arch-general mailing list