写了一个简单的vimscript,用来结合WSL2编辑文件/运行命令
懒得传git了就放在这里,用的时候改一下发行版名称就行。
function! Wsl_path_convert(path_ori)
let path_prefix = '^//wsl\.localhost/Alpine'
return substitute(a:path_ori, path_prefix, '', '')
endfunction
function! Wsl_return_cmd(cmd)
let current_path = expand('%:p:h')
return printf('cd c:/ | execute "!wsl -e sh -c \"cd %s && %s \"" | cd -', Wsl_path_convert(current_path), a:cmd)
endfunction
function! Wsl_return_editexecute(...)
if a:0 == 0
return 'e //wsl.localhost/Alpine/home/xz_st'
else
return 'e //wsl.localhost/Alpine' . a:1
endfunction
" Editor Command Definition
command! -nargs=1 Wslr execute Wsl_return_cmd(<f-args>)
command! -nargs=1 Wslrun execute Wsl_return_cmd(<f-args>)
command! -nargs=? Wsle execute Wsl_return_editexecute(<f-args>)