refactor neovim: 調整chezmoi apply到nvim的結構

This commit is contained in:
2025-04-30 11:05:04 +08:00
parent 9240f60445
commit d8768c6363
26 changed files with 0 additions and 17 deletions

View File

@@ -0,0 +1,2 @@
vim.o.guifont = "MesloLGS NF:h10"
vim.g.neovide_input_ime = true

View File

@@ -0,0 +1,71 @@
-- 這個檔案是依據自己之前在vscode的編輯習慣用來設定editor的鍵盤快捷鍵
-- 處理剪貼簿習慣對應在Insert模式可使用慣用的快速鍵
vim.opt.keymodel = "startsel" -- 啟用 Shift + 方向鍵選取功能
vim.api.nvim_set_keymap('i', '<C-v>', '<Esc>"+pa', { noremap = true, silent = true }) -- Insert Mode 下的 Ctrl+V 貼上
vim.api.nvim_set_keymap('v', '<C-c>', '"+y', { noremap = true, silent = true }) -- Visual Mode 下的 Ctrl+C 複製
vim.api.nvim_set_keymap('v', '<C-x>', '"+d', { noremap = true, silent = true }) -- Visual Mode 下的 Ctrl+X 剪下
vim.api.nvim_set_keymap('v', '<C-v>', '"+p', { noremap = true, silent = true }) -- Visual Mode 下的 Ctrl+V 貼上
-- 整行移動的快速鍵
vim.api.nvim_set_keymap('n', '<A-j>', ':m .+1<CR>==', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<A-k>', ':m .-2<CR>==', { noremap = true, silent = true })
vim.api.nvim_set_keymap('i', '<A-j>', '<Esc>:m .+1<CR>==gi', { noremap = true, silent = true })
vim.api.nvim_set_keymap('i', '<A-k>', '<Esc>:m .-2<CR>==gi', { noremap = true, silent = true })
vim.api.nvim_set_keymap('v', '<A-j>', ":m '>+1<CR>gv=gv", { noremap = true, silent = true })
vim.api.nvim_set_keymap('v', '<A-k>', ":m '<-2<CR>gv=gv", { noremap = true, silent = true })
-- 使用 Alt+方向鍵 移動整行
vim.api.nvim_set_keymap('n', '<A-Down>', ':m .+1<CR>==', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<A-Up>', ':m .-2<CR>==', { noremap = true, silent = true })
vim.api.nvim_set_keymap('i', '<A-Down>', '<Esc>:m .+1<CR>==gi', { noremap = true, silent = true })
vim.api.nvim_set_keymap('i', '<A-Up>', '<Esc>:m .-2<CR>==gi', { noremap = true, silent = true })
vim.api.nvim_set_keymap('v', '<A-Down>', ":m '>+1<CR>gv=gv", { noremap = true, silent = true })
vim.api.nvim_set_keymap('v', '<A-Up>', ":m '<-2<CR>gv=gv", { noremap = true, silent = true })
-- Ctrl+Alt+Shift+j/k 複製整行並向下/向上貼上
vim.api.nvim_set_keymap('n', '<C-A-S-j>', 'yyp', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<C-A-S-k>', 'yyP', { noremap = true, silent = true })
-- Ctrl+Alt+Shift+方向鍵 複製整行並向下/向上貼上
vim.api.nvim_set_keymap('n', '<C-A-S-Down>', 'yyp', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<C-A-S-Up>', 'yyP', { noremap = true, silent = true })
vim.api.nvim_set_keymap('i', '<C-A-S-Down>', '<Esc>yypgi', { noremap = true, silent = true })
vim.api.nvim_set_keymap('i', '<C-A-S-Up>', '<Esc>yyPgi', { noremap = true, silent = true })
-- -- 處理不同終端的行為
-- -- 在 Insert Mode 下的 Ctrl+Enter 在下一行插入新行並保持 Insert 模式
-- local term = vim.fn.getenv("TERM")
-- local term_program = vim.fn.getenv("TERM_PROGRAM")
-- if term_program == "iTerm.app" then
-- -- iTerm 的快捷鍵設置
-- vim.api.nvim_set_keymap('i', '<C-CR>', '<Esc>o', { noremap = true, silent = true })
-- vim.api.nvim_set_keymap('i', '<C-S-CR>', '<Esc>O', { noremap = true, silent = true })
-- elseif term == "alacritty" then
-- -- Alacritty 的快捷鍵設置
-- vim.api.nvim_set_keymap('i', '<C-CR>', '<Esc>o', { noremap = true, silent = true })
-- vim.api.nvim_set_keymap('i', '<C-S-CR>', '<Esc>O', { noremap = true, silent = true })
-- elseif term == "xterm-256color" then
-- -- xterm-256color 的快捷鍵設置
-- vim.api.nvim_set_keymap('i', '<A-CR>', '<Esc>o', { noremap = true, silent = true })
-- vim.api.nvim_set_keymap('i', '<A-S-CR>', '<Esc>O', { noremap = true, silent = true })
-- end
-- 使用Ctrl(Alt)+Enter 在下一行插入新行並保持 Insert 模式
-- 檢查 $TERM 或 $TERM_PROGRAM 的值
-- Alacritty, GUI(Neovide, Goneovim) 皆可
-- xterm-256color採用程式: Konsole, iTerm2, gnome-terminal 會有按鍵吃不到的問題,詳下述註解:
-- 使用Ctrl+Enter 在下一行插入新行並保持 Insert 模式xterm-256color 吃不到)
vim.api.nvim_set_keymap('i', '<C-CR>', '<Esc>o', { noremap = true, silent = true })
vim.api.nvim_set_keymap('i', '<C-S-CR>', '<Esc>O', { noremap = true, silent = true })
-- 使用Alt+Enter 在下一行插入新行並保持 Insert 模式
vim.api.nvim_set_keymap('i', '<A-CR>', '<Esc>o', { noremap = true, silent = true })
vim.api.nvim_set_keymap('i', '<A-S-CR>', '<Esc>O', { noremap = true, silent = true }) -- xterm-256color 吃不到shift
-- 啟用 Tab 縮排
vim.api.nvim_set_keymap('n', '<TAB>', 'v>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<S-TAB>', 'v<', { noremap = true, silent = true })
vim.api.nvim_set_keymap('v', '<TAB>', '>gv', { noremap = true, silent = true })
vim.api.nvim_set_keymap('v', '<S-TAB>', '<gv', { noremap = true, silent = true })
vim.api.nvim_set_keymap('i', '<S-TAB>', '<C-d>', { noremap = true, silent = true }) -- Insert Mode 下的 Shift+Tab 退縮排
-- 透過 v 選取整行縮排後,不取消選取整行
vim.api.nvim_set_keymap('v', '<', '<gv', { noremap = true, silent = true })
vim.api.nvim_set_keymap('v', '>', '>gv', { noremap = true, silent = true })

View File

@@ -0,0 +1,37 @@
-- 這個檔案是用來設定 Neovim 的鍵盤快捷鍵
local map = vim.keymap.set
-- konsole終端限制
-- Esc 會送成 Ctrl+[
-- Ctrl+Enter 鍵會被視為 Ctrl+M (對策: 多增加相同功能的Ctrl+Alt+Enter)
-- <A-S-CR>
-- Ctrl+s 儲存
map("n", "<C-s>", "<cmd>write<CR>", { noremap = true, silent = true, desc = "Save file" })
map("i", "<C-s>", "<Esc><cmd>write<CR>a", { noremap = true, silent = true, desc = "Save file in insert mode" })
-- Tab切換
-- 現在由barbar控制先停用
-- vim.api.nvim_set_keymap('n', '<A-l>', '<cmd>tabnext<CR>', { noremap = true, silent = true })
-- vim.api.nvim_set_keymap('n', '<A-h>', '<cmd>tabprevious<CR>', { noremap = true, silent = true })
-- vim.api.nvim_set_keymap('n', '<A-RIGHT>', '<cmd>tabnext<CR>', { noremap = true, silent = true })
-- vim.api.nvim_set_keymap('n', '<A-LEFT>', '<cmd>tabprevious<CR>', { noremap = true, silent = true })
-- Move to window using the <ctrl> hjkl keys
map("n", "<C-h>", "<C-w>h", { desc = "Go to Left Window", remap = true })
map("n", "<C-j>", "<C-w>j", { desc = "Go to Lower Window", remap = true })
map("n", "<C-k>", "<C-w>k", { desc = "Go to Upper Window", remap = true })
map("n", "<C-l>", "<C-w>l", { desc = "Go to Right Window", remap = true })
map("n", "<C-Left>", "<C-w>h", { desc = "Go to Left Window", remap = true })
map("n", "<C-Down>", "<C-w>j", { desc = "Go to Lower Window", remap = true })
map("n", "<C-Up>", "<C-w>k", { desc = "Go to Upper Window", remap = true })
map("n", "<C-Right>", "<C-w>l", { desc = "Go to Right Window", remap = true })
-- Clear search, diff update and redraw
-- taken from runtime/lua/_editor.lua
-- 原始vim會佔用 <C-l> 快速鍵,導致上述跳窗鍵盤無法靈活此用,故將此按鍵改為 <leader>ur
map(
"n",
"<leader>ur",
"<Cmd>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR>",
{ desc = "Redraw / Clear hlsearch / Diff Update" }
)

View File

@@ -0,0 +1,74 @@
-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)
-- Make sure to setup `mapleader` and `maplocalleader` before
-- loading lazy.nvim so that mappings are correct.
-- This is also a good place to setup other settings (vim.opt)
-- vim.g.mapleader = " "
-- vim.g.maplocalleader = "\\"
-- Setup lazy.nvim
require("lazy").setup({
rocks = {
hererocks = true, -- recommended if you do not have global installation of Lua 5.1.
},
spec = {
-- 先關閉此功能目前在neo-tree無法work而且會造成neovide出問題
-- {
-- "3rd/image.nvim",
-- opts = {},
-- config = function()
-- require("image").setup({
-- backend = "ueberzug", -- or "ueberzug"
-- processor = "magick_rock", -- or "magick_rock"
-- })
-- end,
-- },
-- 自動載入 plugins 資料夾中的所有插件
{ import = "plugins" },
{ import = "plugins.colorscheme.nightfox" }, -- 自訂配色
-- { import = "plugins.colorscheme.github-theme" }, -- 自訂配色
-- { import = "plugins.colorscheme.onedark" }, -- 自訂配色
{ import = "plugins.tab.barbar" }, -- 目前只有barbar處理Buffer是最好的
-- 手動引入 o-plugins 資料夾中的插件
-- require("o-plugins.nvim-listchars"),
},
-- Configure any other settings here. See the documentation for more details.
-- colorscheme that will be used when installing plugins.
install = { colorscheme = { "habamax" } },
-- automatically check for plugin updates
checker = {
enabled = true,
notify = false, -- notify on update
}, -- automatically check for plugin updates
performance = {
rtp = {
-- disable some rtp plugins
disabled_plugins = {
-- "gzip",
-- "matchit",
-- "matchparen",
-- "netrwPlugin",
-- "tarPlugin",
-- "tohtml",
-- "tutor",
-- "zipPlugin",
},
},
},
})

View File

@@ -0,0 +1,14 @@
-- vim.opt.listchars = {
-- eol = "¬",
-- tab = "→→",
-- trail = ".",
-- extends = ">",
-- precedes = "<"
-- }
vim.opt.listchars = {
trail = "-",
eol = "",
tab = "» ",
space = "·",
}

View File

@@ -0,0 +1,24 @@
-- 編輯器行為設定
vim.api.nvim_set_option("clipboard", "unnamedplus") -- 使用系統剪貼簿Wayland有直接支援不須依賴vim-wayland-clipboard
vim.opt.confirm = true -- 操作過程有衝突時,以明確的文字來詢問
vim.opt.history = 10000 -- 設定命令歷史記錄數量為 10000
-- vim.opt.directory = "." -- 將暫存檔存放在當前資料夾中
-- require("config.swap") -- 將暫存檔存放置位置另外做邏輯
vim.opt.mouse = "a" -- 啟用滑鼠支援
-- 編碼設定
vim.opt.encoding = "utf-8"
vim.opt.fileencodings = { "utf-8", "cp950" }
vim.opt.enc = "utf-8"
-- 設定編輯選項
vim.opt.number = true -- 顯示行號
vim.opt.relativenumber = false -- 相對行號
vim.opt.tabstop = 4 -- tab鍵寬度
vim.opt.shiftwidth = 4 -- 自動縮排寬度
vim.opt.expandtab = true -- 使用空格代替tab
vim.opt.termguicolors = true -- 支持真彩色
vim.opt.colorcolumn = "80,120" -- 顯示編輯器建議寬度
vim.opt.scrolloff = 3 -- 捲動時保留 n 行彈性
require("config.listchars") -- 顯示行尾符號
vim.opt.list = true

View File

@@ -0,0 +1,32 @@
-- ### **邏輯說明**
-- 1. **測試檔案建立**
-- - 嘗試在當前資料夾中建立一個測試檔案(`.nvim_swap_test`)。
-- - 如果成功,則將 `directory` 設定為 `.`(當前資料夾)。
-- - 如果失敗(例如因為權限問題),則回退到 Neovim 的預設暫存檔位置。
-- 2. **回退位置**
-- - 使用 `vim.fn.stdpath("data")`,這是 Neovim 的資料目錄(通常是 `~/.local/share/nvim/swap/`)。
-- - 確保回退位置存在,並且不會影響正常使用。
-- 3. **通知使用者**
-- - 如果回退到預設位置,會透過 `vim.notify` 提醒使用者。
-- 嘗試將暫存檔存放在當前資料夾中
local function set_swap_directory()
local current_dir = "."
local test_file = current_dir .. "/.nvim_swap_test"
-- 嘗試建立測試檔案
local file, err = io.open(test_file, "w")
if file then
file:close()
os.remove(test_file) -- 刪除測試檔案
vim.opt.directory = current_dir -- 成功,將暫存檔存放在當前資料夾
else
-- 無法建立測試檔案,回退到 Neovim 預設位置
vim.opt.directory = vim.fn.stdpath("data") .. "/swap//"
vim.notify("無法在當前資料夾建立暫存檔,改用預設位置: " .. vim.opt.directory:get(), vim.log.levels.WARN)
end
end
set_swap_directory()

View File

@@ -0,0 +1,17 @@
-- 設置終端顏色
vim.g.terminal_color_0 = "#3b4252" -- 黑色
vim.g.terminal_color_1 = "#bf616a" -- 紅色
vim.g.terminal_color_2 = "#a3be8c" -- 綠色
vim.g.terminal_color_3 = "#ebcb8b" -- 黃色
vim.g.terminal_color_4 = "#81a1c1" -- 藍色
vim.g.terminal_color_5 = "#b48ead" -- 紫色
vim.g.terminal_color_6 = "#88c0d0" -- 青色
vim.g.terminal_color_7 = "#d8dee9" -- 白色
vim.g.terminal_color_8 = "#3b4252" -- 亮黑色(灰色)
vim.g.terminal_color_9 = "#bf616a" -- 亮紅色
vim.g.terminal_color_10 = "#a3be8c" -- 亮綠色
vim.g.terminal_color_11 = "#ebcb8b" -- 亮黃色
vim.g.terminal_color_12 = "#81a1c1" -- 亮藍色
vim.g.terminal_color_13 = "#b48ead" -- 亮紫色
vim.g.terminal_color_14 = "#88c0d0" -- 亮青色
vim.g.terminal_color_15 = "#d8dee9" -- 亮白色