【发布时间】:2022-10-01 15:44:33
【问题描述】:
我需要一个命令,将剪贴板的内容设置为通过管道传输到其输入的任何内容,而无需添加尾随换行符。以下:
C:> *some_command* | clip.exe
在末尾添加换行符,同时:
C:> *some_command* | powershell.exe Set-Clipboard
似乎没有将标准输入传递给Set-Clipboard。不能通过 powershell 提示调用 *some_command*。我怎样才能做我需要的?
背景:我正在使用 WSL,我希望能够从 vim、tmux 等复制/粘贴到系统剪贴板。我当前的解决方法是使用 clip.exe,它会在我拉出的任何内容中添加一个换行符。例如,在.vimrc 我have:
let g:copy = \'clip.exe\'
let g:paste = \'powershell.exe Get-Clipboard -Raw\'
augroup myYank
autocmd!
autocmd TextYankPost * if v:event.operator == \'y\' | call system(g:copy, @\") | let g:lastyank=\'y\' | else | let g:lastyank=\'\' | endif
\"autocmd TextYankPost * if v:event.operator ==# \'y\' | call system(g:copy, @\") | endif
\"autocmd TextYankPost * call system(g:copy, @\")
augroup END
function! Paste(mode)
if g:lastyank == \'y\'
let @\" = system(g:paste)
endif
return a:mode
endfunction
map <expr> p Paste(\'p\')
map <expr> P Paste(\'P\')
\" map Ctrl-c and Ctrl-x as expected
func! GetSelectedText()
normal gv\"xy
let result = getreg(\"x\")
return result
endfunc
noremap <C-c> :call system(g:copy, GetSelectedText())<CR>
noremap <C-x> :call system(g:copy, GetSelectedText())<CR>gvx
标签: clipboard windows-subsystem-for-linux