适配wsl环境

This commit is contained in:
caprain 2026-05-03 21:21:16 +08:00
parent ca576a6090
commit fea05914e5
3 changed files with 43 additions and 13 deletions

View file

@ -19,6 +19,9 @@ if vim.g.neovide then
if not IS_ARM then
vim.env.HTTP_PROXY = "http://127.0.0.1:7897"
vim.env.HTTPS_PROXY = "http://127.0.0.1:7897"
if vim.fn.has("wsl") == 1 then
vim.o.guifont = "Ioskeley_Mono,Noto_Sans_CJK_SC:h12.5"
end
else
vim.o.guifont = "Ioskeley_Mono,Noto_Sans_CJK_SC:h24"
end

View file

@ -62,15 +62,6 @@ vim.o.undofile = true
-- 打开文件时进入上次编辑的位置
vim.cmd([[au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif]])
-- fcitx5在normal模式时自动切换为英文输入法,摘自fcitx5的archwiki
vim.cmd([[
autocmd InsertLeave * :silent !fcitx5-remote -c
autocmd BufCreate * :silent !fcitx5-remote -c
autocmd BufEnter * :silent !fcitx5-remote -c
autocmd BufLeave * :silent !fcitx5-remote -c
]])
-- 意为: 当 进入插入模式、创建Buf、进入Buf、离开Buf 时 触发shell命令 fcitx-remote -c 关闭输入法,改为英文输入
-- 架构判断
local arch = jit and jit.arch or ""
_G.IS_ARM = arch:match("arm") or arch:match("aarch64") ~= nil
@ -97,10 +88,10 @@ vim.api.nvim_create_autocmd("FileType", {
pattern = "log",
callback = function()
-- 这里的 fg 是十六进制颜色,你可以根据喜好调整
vim.api.nvim_set_hl(0, "LogVersion", { fg = "#50FA7B", bold = true }) -- 绿色
vim.api.nvim_set_hl(0, "LogDownloaded", { fg = "#BD93F9" }) -- 紫色
vim.api.nvim_set_hl(0, "LogCompiling", { fg = "#F1FA8C" }) -- 黄色
vim.api.nvim_set_hl(0, "LogFinished", { fg = "#8BE9FD", bold = true }) -- 青色
vim.api.nvim_set_hl(0, "LogVersion", { fg = "#50FA7B", bold = true })
vim.api.nvim_set_hl(0, "LogDownloaded", { fg = "#BD93F9" })
vim.api.nvim_set_hl(0, "LogCompiling", { fg = "#F1FA8C" })
vim.api.nvim_set_hl(0, "LogFinished", { fg = "#8BE9FD", bold = true })
-- 清除旧的匹配,防止重复渲染卡顿
for _, match in ipairs(vim.fn.getmatches()) do
if match.group:find("^Log") then
@ -116,6 +107,39 @@ vim.api.nvim_create_autocmd("FileType", {
end,
})
-- https://github.com/daipeihust/im-select
local im_select_path = "/mnt/d/my_program/Rime/im-select.exe"
local arg = "1033" -- 美式键盘直接运行im-select可以获取当前输入法的key
if vim.fn.has("wsl") == 1 then
-- wsl环境调用特殊剪切板
vim.g.clipboard = {
name = "WslClipboard",
copy = {
["+"] = "win32yank.exe -i --crlf",
["*"] = "win32yank.exe -i --crlf",
},
paste = {
["+"] = "win32yank.exe -o --lf",
["*"] = "win32yank.exe -o --lf",
},
cache_enabled = 0,
}
vim.api.nvim_create_autocmd("InsertLeave", {
callback = function()
vim.fn.jobstart({ im_select_path, arg }, { detach = true })
end,
})
else
-- fcitx5在normal模式时自动切换为英文输入法,摘自fcitx5的archwiki
vim.cmd([[
autocmd InsertLeave * :silent !fcitx5-remote -c
autocmd BufCreate * :silent !fcitx5-remote -c
autocmd BufEnter * :silent !fcitx5-remote -c
autocmd BufLeave * :silent !fcitx5-remote -c
]])
-- 意为: 当 进入插入模式、创建Buf、进入Buf、离开Buf 时 触发shell命令 fcitx-remote -c 关闭输入法,改为英文输入
end
-- 开启高亮复制
vim.cmd([[au TextYankPost * silent! lua vim.highlight.on_yank()]])

View file

@ -18,6 +18,9 @@ vim.api.nvim_create_user_command("PeekToggle", function()
app = { "chromium", "--no-sandbox", "--app=http://localhost:9000/?theme=dark", "--incognito", "--test-type",
"--force-device-scale-factor=1.75" }
end
if vim.fn.has("wsl") == 1 then
app = { "/mnt/d/my_program/chrome-win/chrome.exe", "--no-sandbox", "--app=http://localhost:9000/?theme=dark", "--incognito", "--test-type" }
end
require("peek").setup({
port = 9000,
-- app = { "zen", "-private-window" },