(Yank Cygwin vim content to the Windows clipboard) |
No edit summary |
||
Line 3: | Line 3: | ||
Using this function: |
Using this function: |
||
− | <pre>function! Putclip() |
+ | <pre>function! Putclip(type, ...) range |
− | let |
+ | let sel_save = &selection |
− | let |
+ | let &selection = "inclusive" |
− | + | let reg_save = @@ |
|
+ | |||
⚫ | |||
+ | if a:type == 'n' |
||
− | call setreg('z', save_z, save_z_type) |
||
+ | silent exe a:firstline . "," . a:lastline . "y" |
||
+ | elseif a:type == 'c' |
||
+ | silent exe a:1 . "," . a:2 . "y" |
||
+ | else |
||
+ | silent exe "normal! `<" . a:type . "`>y" |
||
+ | endif |
||
⚫ | |||
+ | |||
+ | let &selection = sel_save |
||
+ | let @@ = reg_save |
||
endfunction</pre> |
endfunction</pre> |
||
− | And |
+ | And simple mappings, such as: |
+ | |||
⚫ | |||
+ | nnoremap <silent> <leader>y :call Putclip('n', 1)<CR></pre> |
||
+ | |||
⚫ | |||
+ | To allow for usage from the command line, add a command to execute Putclip with a range: |
||
⚫ | |||
+ | <pre>com! -nargs=0 -range=% Putclip call Putclip('c', <line1>, <line2>)</pre> |
||
⚫ |
Revision as of 03:27, 10 April 2009
One of the challenges of using Cygwin vim is that it does not yank to the Windows clipboard when you type "+y. As a result, you cannot access any content you've yanked from Cygwin vim with any native Windows application.
Using this function:
function! Putclip(type, ...) range let sel_save = &selection let &selection = "inclusive" let reg_save = @@ if a:type == 'n' silent exe a:firstline . "," . a:lastline . "y" elseif a:type == 'c' silent exe a:1 . "," . a:2 . "y" else silent exe "normal! `<" . a:type . "`>y" endif call system('putclip', @@) let &selection = sel_save let @@ = reg_save endfunction
And simple mappings, such as:
vnoremap <silent> <leader>y :call Putclip(visualmode(), 1)<CR> nnoremap <silent> <leader>y :call Putclip('n', 1)<CR>
You can visually select some text then yank it to the Windows clipboard, or use the normal yank options (i.e. 3\y to yank 3 lines based from the current line).
To allow for usage from the command line, add a command to execute Putclip with a range:
com! -nargs=0 -range=% Putclip call Putclip('c', <line1>, <line2>)