fix encoding when yanking to windows in vim

This commit is contained in:
Felix Pankratz 2025-10-01 10:59:30 +02:00
parent bf585170ac
commit 352ff322e1

37
.vimrc
View File

@ -18,6 +18,10 @@ Plugin 'pearofducks/ansible-vim'
Plugin 'mechatroner/rainbow_csv'
" ChatGPT plugin
Plugin 'CamdenClark/flyboy'
" Aider
Plugin 'joshuavial/aider.nvim'
" Black
Plugin 'psf/black'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
@ -72,13 +76,37 @@ set statusline +=%2*0x%04B\ %* "character under cursor
" Copy to clipboard
" set clipboard=unnamedplus
if system('uname -r') =~ "Microsoft"
augroup Yank
"if system('uname -r') =~ "Microsoft"
" augroup Yank
" autocmd!
" autocmd TextYankPost * :call system('/mnt/c/windows/system32/clip.exe ',@")
" augroup END
"endif
" only on WSL
if has('unix') && system('uname -r') =~ 'Microsoft'
augroup YankToWindowsClipboard
autocmd!
autocmd TextYankPost * :call system('/mnt/c/windows/system32/clip.exe ',@")
autocmd TextYankPost * call s:WslYank()
augroup END
function! s:WslYank() abort
" get the yanked text
let l:txt = @"
" shell-escape it
let l:esc = shellescape(l:txt)
" pipe through iconv to UTF-16LE, then into clip.exe
call system(
\ 'printf %s '.l:esc.
\ ' | iconv -f utf-8 -t utf-16le'.
\ ' | /mnt/c/Windows/System32/clip.exe'
\ )
endfunction
endif
"map <silent> "=p :r !powershell.exe -Command Get-Clipboard<CR>
"map! <silent> <C-r>= :r !powershell.exe -Command Get-Clipboard<CR>
"noremap "+p :exe 'norm a'.system('/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command Get-Clipboard')<CR>
@ -108,7 +136,8 @@ endif
" generate pw?
" r! cmd.exe /c 'python C:\Tools\pw.py 10'
" =system("cmd.exe /c 'python C:\\Tools\\pw.py 10' | tr -d '\n' | tr -d '\r'")
let pwcmd = 'cmd.exe /c "python C:\\Tools\\pw.py 10" |tr -d "\\n"|tr -d "\\r"'
"let pwcmd = 'cmd.exe /c "python C:\\Tools\\pw.py 10" |tr -d "\\n"|tr -d "\\r"'
let pwcmd = 'powershell.exe -command "python C:\\Tools\\pw.py 10" |tr -d "\\n"|tr -d "\\r"'
:nmap <F8> "=system(pwcmd)<C-M>p
:imap <F8> <C-R>=system(pwcmd)<C-M>