切換nvim資料夾為exact: chezmoi add -r --exact ~/.config/nvim

This commit is contained in:
2025-04-29 12:16:18 +08:00
parent 0b94b839d9
commit 6b8d7b79e3
18 changed files with 29 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,51 @@
-- 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 = {
{
"3rd/image.nvim",
opts = {},
config = function()
require("image").setup({
backend = "ueberzug", -- or "ueberzug"
processor = "magick_rock", -- or "magick_rock"
})
end,
},
-- 自動載入 plugins 資料夾中的所有插件
{ import = "plugins" },
-- 手動引入 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 },
})

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,94 @@
-- 編輯器行為設定
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
-- 處理剪貼簿習慣對應在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,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()