From 923ddadd52a1d017381008ef4ab4d3f2b8607dfc Mon Sep 17 00:00:00 2001 From: rebuildup Date: Mon, 23 Nov 2026 20:54:34 +0900 Subject: [PATCH] feat(editor): deploy Unix Vim/Neovim entry points safely Add ~/.vimrc and ~/.config/nvim/init.lua for POSIX while keeping the Windows %LOCALAPPDATA% entries under home/AppData. Move the canonical Neovim config to home/vimfiles/nvim/init.lua behind byte-identical thin loaders, and make POSIX link/check skip AppData while link.ps1 skips the POSIX-only entry points. Existing unmanaged state is never removed. Supersedes the stale PR #84 approach on the current managed-targets layout. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- README.md | 8 +- home/.config/nvim/init.lua | 11 + home/.vimrc | 22 + home/AppData/Local/nvim/init.lua | 833 +------------------------------ home/vimfiles/nvim/init.lua | 826 ++++++++++++++++++++++++++++++ script/lib/managed-targets.sh | 11 + script/link.ps1 | 2 + 7 files changed, 886 insertions(+), 827 deletions(-) create mode 100644 home/.config/nvim/init.lua create mode 100644 home/.vimrc create mode 100644 home/vimfiles/nvim/init.lua diff --git a/README.md b/README.md index bbd369d..6dbef2f 100644 --- a/README.md +++ b/README.md @@ -247,11 +247,13 @@ The current common Git baseline includes: - global ignore via `~/.config/git/ignore` - machine/user-local `~/.gitconfig.local` -The editor baseline is shared between Vim and Neovim: +The editor baseline is shared between Vim and Neovim. Each OS has only a thin +entry point; the configuration itself lives once under `home/vimfiles/`: -- `~/vimfiles/shared/base.vim` — the single source of truth for both editors (encoding, `~/.cache/vim` backup/swap/undo, display, folding, search, indent, statusline, `list`, window/tab/normal/insert/visual mappings, transparent background). Sourced by Vim's `_vimrc` and by Neovim's `init.lua`. +- `~/vimfiles/shared/base.vim` — the single source of truth for both editors (encoding, `~/.cache/vim` backup/swap/undo, display, folding, search, indent, statusline, `list`, window/tab/normal/insert/visual mappings, transparent background). - `~/vimfiles/keymap/onishi.vim` — 大西配列 key placement; sourced last from `base.vim` so it overrides the defaults above. -- `%LOCALAPPDATA%\Programs\Vim\_vimrc` and `%LOCALAPPDATA%\nvim\` (Neovim config, lockfiles, `scripts/`, `snippets/`) mirror their real Windows locations under `home/AppData/Local/` so neither editor needs an environment variable to find its config. +- `~/vimfiles/nvim/init.lua` — the canonical Neovim config. `home/.config/nvim/init.lua` (POSIX) and `home/AppData/Local/nvim/init.lua` (Windows) are byte-identical thin loaders of that file. +- Entry points: `home/.vimrc` → `~/.vimrc` on macOS/WSL; `%LOCALAPPDATA%\Programs\Vim\_vimrc` and `%LOCALAPPDATA%\nvim\init.lua` at their real Windows locations via `home/AppData/Local/`. `script/link` skips `home/AppData/` on POSIX and `script/link.ps1` skips `home/.vimrc` / `home/.config/nvim/` on Windows; skipped sources are never deleted. `set background=transparent` is rejected with E474 by both Vim and Neovim, so transparency is applied as `guibg=NONE` on `Normal` / `NormalNC` / `SignColumn` / `EndOfBuffer`, re-applied on `ColorScheme`. diff --git a/home/.config/nvim/init.lua b/home/.config/nvim/init.lua new file mode 100644 index 0000000..187e414 --- /dev/null +++ b/home/.config/nvim/init.lua @@ -0,0 +1,11 @@ +-- Thin Neovim entry point. Windows reads it from %LOCALAPPDATA%\nvim +-- (home/AppData/Local/nvim/init.lua), POSIX from ~/.config/nvim +-- (home/.config/nvim/init.lua); the two files are byte-identical on purpose +-- and source the one canonical config, home/vimfiles/nvim/init.lua, so the +-- configuration is never duplicated across operating systems. +local shared = vim.fn.expand("~/vimfiles/nvim/init.lua") +if vim.fn.filereadable(shared) == 1 then + vim.cmd.source(shared) +else + vim.notify("dotfiles: missing " .. shared .. " (run script/link)", vim.log.levels.WARN) +end diff --git a/home/.vimrc b/home/.vimrc new file mode 100644 index 0000000..d4fd879 --- /dev/null +++ b/home/.vimrc @@ -0,0 +1,22 @@ +" POSIX entry point for Vim. Windows uses the install-dir entry at +" home/AppData/Local/Programs/Vim/_vimrc; both files only source shared +" configuration, nothing is configured here. +" +" vimrc_example.vim is the portable runtime template (its own header says +" "for Unix: ~/.vimrc") and it pulls in $VIMRUNTIME/defaults.vim. Sourcing it +" matters on Unix: with a user vimrc present Vim no longer auto-loads +" defaults.vim, so skipping the template would regress scrolloff/mouse/ttimeout +" that this machine has today. base.vim runs last and overrides every option it +" shares with the template, in the same order as the Windows entry. +if filereadable(expand('$VIMRUNTIME/vimrc_example.vim')) + source $VIMRUNTIME/vimrc_example.vim +endif + +" The Windows-only `set diffexpr=MyDiff()` block is intentionally skipped: +" Vim 9 lists 'internal' in 'diffopt' on every platform (verified: +" diffopt=internal,filler,...), so MyDiff never runs on Windows either. + +" 共通設定 (大西配列のキーマップ・背景透過を含む) +if filereadable(expand("~/vimfiles/shared/base.vim")) + source ~/vimfiles/shared/base.vim +endif diff --git a/home/AppData/Local/nvim/init.lua b/home/AppData/Local/nvim/init.lua index 872843f..187e414 100644 --- a/home/AppData/Local/nvim/init.lua +++ b/home/AppData/Local/nvim/init.lua @@ -1,826 +1,11 @@ -local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" - -if not vim.loop.fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", - lazypath, - }) -end - -vim.opt.rtp:prepend(lazypath) - --- 起動時パフォーマンス: 未使用providerを無効化 -vim.g.loaded_perl_provider = 0 -vim.g.loaded_ruby_provider = 0 -vim.g.loaded_node_provider = 0 -vim.g.loaded_python3_provider = 0 - -vim.opt.shadafile = "NONE" -vim.opt.updatetime = 300 -vim.opt.signcolumn = "yes" -vim.opt.lazyredraw = false - --- リーダーキー -vim.g.mapleader = " " -vim.g.maplocalleader = "\\" - -require("lazy").setup({ - spec = { - -- ============================================================= - -- Core: Treesitter (構文解析・ハイライト・テキストオブジェクト) - -- ============================================================= - { - "nvim-treesitter/nvim-treesitter", - build = ":TSUpdate", - event = { "BufReadPost", "BufNewFile" }, - cmd = { "TSUpdateSync", "TSInstall", "TSUninstall" }, - opts = { - ensure_installed = { - "bash", - "c", - "cpp", - "css", - "html", - "javascript", - "json", - "jsonc", - "lua", - "markdown", - "markdown_inline", - "python", - "query", - "regex", - "rust", - "toml", - "tsx", - "typescript", - "vim", - "vimdoc", - "yaml", - }, - auto_install = true, - highlight = { enable = true, additional_vim_regex_highlighting = false }, - indent = { enable = true }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = "", - node_incremental = "", - scope_incremental = false, - node_decremental = "", - }, - }, - textobjects = { - select = { - enable = true, - lookahead = true, - keymaps = { - ["af"] = "@function.outer", - ["if"] = "@function.inner", - ["ac"] = "@class.outer", - ["ic"] = "@class.inner", - ["aa"] = "@parameter.outer", - ["ia"] = "@parameter.inner", - }, - }, - move = { - enable = true, - set_jumps = true, - goto_next_start = { ["]f"] = "@function.outer", ["]c"] = "@class.outer" }, - goto_previous_start = { ["[f"] = "@function.outer", ["[c"] = "@class.outer" }, - }, - }, - }, - config = function(_, opts) - require("nvim-treesitter.config").setup(opts) - end, - }, - { - "nvim-treesitter/nvim-treesitter-textobjects", - event = { "BufReadPost", "BufNewFile" }, - }, - - -- ============================================================= - -- File Explorer: oil.nvim (バッファベース、軽量) - -- ============================================================= - { - "stevearc/oil.nvim", - cmd = "Oil", - keys = { - { "e", "Oil", desc = "File explorer" }, - { "E", "Oil .", desc = "File explorer (cwd)" }, - }, - opts = { - default_file_explorer = true, - columns = { "icon", "permissions", "size", "mtime" }, - keymaps = { - ["g?"] = "actions.show_help", - [""] = "actions.select", - [""] = { "actions.select", opts = { vertical = true }, desc = "Open in vertical split" }, - [""] = { "actions.select", opts = { horizontal = true }, desc = "Open in horizontal split" }, - [""] = { "actions.select", opts = { tab = true }, desc = "Open in new tab" }, - [""] = "actions.preview", - [""] = "actions.close", - [""] = "actions.refresh", - ["-"] = "actions.parent", - ["_"] = "actions.open_cwd", - ["`"] = "actions.cd", - ["~"] = { "actions.cd", opts = { scope = "tab" }, desc = "cd to home" }, - ["gs"] = "actions.change_sort", - ["gx"] = "actions.open_external", - ["g."] = "actions.toggle_hidden", - ["g\\"] = "actions.toggle_trash", - }, - view_options = { - show_hidden = true, - is_always_hidden = function(name, _) - return name == ".." or name == ".git" - end, - }, - float = { - padding = 2, - max_width = 0.8, - max_height = 0.8, - border = "rounded", - }, - }, - }, - - -- ============================================================= - -- Completion: blink.cmp (高速、LSP統合) - -- ============================================================= - { - "saghen/blink.cmp", - version = "1.*", - dependencies = { - "L3MON4D3/LuaSnip", - "rafamadriz/friendly-snippets", - }, - event = { "BufReadPost", "BufNewFile" }, - opts = { - keymap = { - preset = "none", - [""] = { "select_next", "fallback" }, - [""] = { "select_prev", "fallback" }, - [""] = { "show", "fallback" }, - [""] = { "hide", "fallback" }, - [""] = { "scroll_documentation_down", "fallback" }, - [""] = { "scroll_documentation_up", "fallback" }, - [""] = { "select_and_accept" }, - -- Tab: snippet次 → 候補確定(選択済みをaccept、未選択なら先頭をaccept) → 通常Tab - [""] = { "snippet_forward", "select_and_accept", "fallback" }, - -- Shift+Tab: snippet前 → 候補を前へ → 通常Shift+Tab - [""] = { "snippet_backward", "select_prev", "fallback" }, - [""] = { "accept", "fallback" }, - }, - cmdline = { - enabled = true, - keymap = { - preset = "inherit", - [""] = { "show_and_insert", "select_next" }, - [""] = { "show_and_insert", "select_prev" }, - }, - }, - completion = { - documentation = { - auto_show = true, - auto_show_delay_ms = 200, - window = { border = "rounded" }, - }, - menu = { - border = "rounded", - draw = { - columns = { - { "kind_icon", "label", "label_description", gap = 1 }, - { "source_name" }, - }, - }, - }, - ghost_text = { enabled = true }, - }, - signature = { - enabled = true, - window = { border = "rounded" }, - }, - sources = { - default = { "lsp", "path", "snippets", "buffer" }, - providers = { - snippets = { - name = "snippets", - module = "blink.cmp.sources.snippets", - score_offset = 4, - }, - }, - }, - snippets = { preset = "luasnip" }, - }, - config = function(_, opts) - require("blink.cmp").setup(opts) - end, - }, - - -- ============================================================= - -- Snippets: LuaSnip (VS Code形式対応、高機能) - -- ============================================================= - { - "L3MON4D3/LuaSnip", - version = "v2.*", - build = "make install_jsregexp", - event = { "BufReadPost", "BufNewFile" }, - dependencies = { - "rafamadriz/friendly-snippets", - }, - opts = { - history = true, - delete_check_events = "TextChanged", - enable_autosnippets = true, - }, - config = function(_, opts) - require("luasnip").setup(opts) - -- ドットファイル管理のスニペットディレクトリを読み込み - local snippet_dir = vim.fn.expand("~/.dotfiles/home/snippets") - if vim.fn.isdirectory(snippet_dir) == 1 then - require("luasnip.loaders.from_vscode").load({ paths = { snippet_dir } }) - end - -- friendly-snippetsも読み込み (package.jsonがルートにあるため明示的なパス指定が必要) - local friendly_dir = vim.fn.expand("~/.local/share/nvim/lazy/friendly-snippets") - if vim.fn.isdirectory(friendly_dir) == 1 then - require("luasnip.loaders.from_vscode").load({ paths = { friendly_dir } }) - end - end, - }, - - -- ============================================================= - -- Git: gitsigns.nvim (サイン表示) + diffview.nvim (差分表示) - -- ============================================================= - { - "lewis6991/gitsigns.nvim", - event = { "BufReadPost", "BufNewFile" }, - opts = { - signs = { - add = { text = "▎" }, - change = { text = "▎" }, - delete = { text = "" }, - topdelete = { text = "" }, - changedelete = { text = "▎" }, - untracked = { text = "▎" }, - }, - signcolumn = true, - numhl = false, - linehl = false, - word_diff = false, - watch_gitdir = { interval = 1000, follow_files = true }, - attach_to_untracked = true, - current_line_blame = false, - current_line_blame_opts = { virt_text = true, virt_text_pos = "eol", delay = 500 }, - preview_config = { border = "rounded" }, - on_attach = function(bufnr) - local gs = package.loaded.gitsigns - local function map(mode, l, r, desc) - vim.keymap.set(mode, l, r, { buffer = bufnr, desc = desc }) - end - map("n", "]h", gs.next_hunk, "Next hunk") - map("n", "[h", gs.prev_hunk, "Prev hunk") - map("n", "hs", gs.stage_hunk, "Stage hunk") - map("n", "hr", gs.reset_hunk, "Reset hunk") - map("n", "hS", gs.stage_buffer, "Stage buffer") - map("n", "hu", gs.undo_stage_hunk, "Undo stage hunk") - map("n", "hp", gs.preview_hunk, "Preview hunk") - map("n", "hb", function() gs.blame_line({ full = true }) end, "Blame line") - map("n", "hd", gs.diffthis, "Diff this") - map("n", "hD", function() gs.diffthis("~") end, "Diff this ~") - map("n", "tb", gs.toggle_current_line_blame, "Toggle blame line") - map("n", "td", gs.toggle_deleted, "Toggle deleted") - end, - }, - }, - { - "sindrets/diffview.nvim", - cmd = { "DiffviewOpen", "DiffviewClose", "DiffviewFileHistory" }, - keys = { - { "gd", "DiffviewOpen", desc = "Git diff view" }, - { "gD", "DiffviewClose", desc = "Close diff view" }, - { "gh", "DiffviewFileHistory", desc = "Git file history" }, - }, - opts = { - enhanced_diff_hl = true, - view = { - default = { winbar_info = true }, - merge_tool = { layout = "diff3_mixed" }, - }, - }, - }, - - -- ============================================================= - -- Search: telescope.nvim (ファイル・全文検索) - -- ============================================================= - { - "nvim-telescope/telescope.nvim", - cmd = "Telescope", - keys = { - { "ff", "Telescope find_files", desc = "Find files" }, - { "fg", "Telescope live_grep", desc = "Live grep" }, - { "fb", "Telescope buffers", desc = "Buffers" }, - { "fh", "Telescope help_tags", desc = "Help tags" }, - { "fs", "Telescope lsp_document_symbols", desc = "Document symbols" }, - { "fS", "Telescope lsp_workspace_symbols", desc = "Workspace symbols" }, - { "fr", "Telescope lsp_references", desc = "References" }, - { "fd", "Telescope diagnostics", desc = "Diagnostics" }, - { "fk", "Telescope keymaps", desc = "Keymaps" }, - { "fc", "Telescope commands", desc = "Commands" }, - { "fm", "Telescope marks", desc = "Marks" }, - { "fo", "Telescope oldfiles", desc = "Recent files" }, - }, - dependencies = { - "nvim-lua/plenary.nvim", - { "nvim-telescope/telescope-fzf-native.nvim", build = "make" }, - }, - opts = { - defaults = { - prompt_prefix = " ", - selection_caret = " ", - border = "rounded", - sorting_strategy = "ascending", - layout_config = { - horizontal = { prompt_position = "top", preview_width = 0.55 }, - vertical = { mirror = false }, - width = 0.87, - height = 0.80, - }, - mappings = { - i = { - [""] = "move_selection_next", - [""] = "move_selection_previous", - [""] = "send_to_qflist", - [""] = "send_selected_to_qflist", - }, - }, - }, - pickers = { - find_files = { hidden = true, follow = true }, - buffers = { sort_lastused = true, ignore_current_buffer = true }, - }, - }, - config = function(_, opts) - require("telescope").setup(opts) - pcall(require("telescope").load_extension, "fzf") - end, - }, - - -- ============================================================= - -- Formatter: conform.nvim (保存時フォーマット) - -- ============================================================= - { - "stevearc/conform.nvim", - event = { "BufWritePre" }, - cmd = { "ConformInfo" }, - keys = { - { "cf", function() require("conform").format({ async = true, lsp_format = "fallback" }) end, desc = "Format buffer" }, - }, - opts = { - format_on_save = { timeout_ms = 1000, lsp_format = "fallback" }, - formatters_by_ft = { - rust = { "rustfmt" }, - lua = { "stylua" }, - python = { "ruff_format" }, - javascript = { "prettier" }, - typescript = { "prettier" }, - javascriptreact = { "prettier" }, - typescriptreact = { "prettier" }, - json = { "prettier" }, - jsonc = { "prettier" }, - css = { "prettier" }, - html = { "prettier" }, - markdown = { "prettier" }, - yaml = { "prettier" }, - toml = { "taplo" }, - sh = { "shfmt" }, - c = { "clang_format" }, - cpp = { "clang_format" }, - }, - }, - }, - - -- ============================================================= - -- LSP: nvim-lspconfig + mason.nvim - -- ============================================================= - { - "mason-org/mason.nvim", - cmd = { "Mason", "MasonInstall", "MasonUninstall", "MasonUpdate" }, - keys = { { "mi", "Mason", desc = "Mason" } }, - opts = {}, - }, - { - "neovim/nvim-lspconfig", - event = { "BufReadPost", "BufNewFile" }, - dependencies = { "mason-org/mason.nvim" }, - }, - - -- ============================================================= - -- UI: which-key.nvim (キーマップガイド) - -- ============================================================= - { - "folke/which-key.nvim", - event = "VeryLazy", - opts = { - preset = "modern", - delay = 300, - icons = { mappings = true, rules = {} }, - spec = { - { "f", group = "Find/Search" }, - { "g", group = "Git" }, - { "h", group = "Git Hunk" }, - { "c", group = "Code/Format" }, - { "l", group = "LSP" }, - { "t", group = "Toggle/Terminal" }, - { "w", group = "Window" }, - { "b", group = "Buffer" }, - { "x", group = "Diagnostics" }, - { "a", group = "Cargo/Action" }, - { "g", group = "Goto" }, - { "[", group = "Prev" }, - { "]", group = "Next" }, - }, - }, - }, - - -- ============================================================= - -- UI: mini.nvim (statusline, pairs, etc.) - -- ============================================================= - { - "echasnovski/mini.nvim", - version = "*", - event = { "BufReadPost", "BufNewFile" }, - config = function() - -- mini.pairs: 自動括弧補完 - require("mini.pairs").setup({ - modes = { insert = true, command = false, terminal = false }, - }) - - -- mini.statusline: ステータスライン - require("mini.statusline").setup({ - use_icons = vim.g.have_nerd_font, - content = { - active = function() - local mode, mode_hl = MiniStatusline.section_mode({ trunc_width = 120 }) - local git = MiniStatusline.section_git({ trunc_width = 40 }) - local diff = MiniStatusline.section_diff({ trunc_width = 75 }) - local diagnostics = MiniStatusline.section_diagnostics({ trunc_width = 75 }) - local filename = MiniStatusline.section_filename({ trunc_width = 140 }) - local fileinfo = MiniStatusline.section_fileinfo({ trunc_width = 120 }) - local location = MiniStatusline.section_location({ trunc_width = 75 }) - local search = MiniStatusline.section_searchcount({ trunc_width = 75 }) - - return MiniStatusline.combine_groups({ - { hl = mode_hl, strings = { mode } }, - { hl = "MiniStatuslineDevinfo", strings = { git, diff, diagnostics } }, - "%<", - { hl = "MiniStatuslineFilename", strings = { filename } }, - "%=", - { hl = "MiniStatuslineFileinfo", strings = { fileinfo } }, - { hl = mode_hl, strings = { location, search } }, - }) - end, - }, - }) - - -- mini.icons: アイコン - require("mini.icons").setup() - - -- mini.ai: テキストオブジェクト拡張 - require("mini.ai").setup({ - custom_textobjects = { - f = require("mini.ai").gen_spec.treesitter({ a = "@function.outer", i = "@function.inner" }), - c = require("mini.ai").gen_spec.treesitter({ a = "@class.outer", i = "@class.inner" }), - }, - }) - - -- mini.surround: 囲み操作 - require("mini.surround").setup({ - mappings = { - add = "gsa", - delete = "gsd", - find = "gsf", - find_left = "gsF", - highlight = "gsh", - replace = "gsr", - update_n_lines = "gsn", - }, - }) - end, - }, - - -- ============================================================= - -- Terminal & UI: snacks.nvim (ターミナル、ピッカー、通知等) - -- ============================================================= - { - "folke/snacks.nvim", - priority = 1000, - lazy = false, - keys = { - { "tt", function() Snacks.terminal.toggle() end, desc = "Toggle terminal" }, - { "tf", function() Snacks.terminal.toggle(nil, { win = { position = "float" } }) end, desc = "Float terminal" }, - { "tb", function() Snacks.terminal.toggle(nil, { win = { position = "bottom" } }) end, desc = "Bottom terminal" }, - { "tr", function() Snacks.terminal.toggle("lazygit") end, desc = "Lazygit" }, - { "tn", function() Snacks.notifier.show_history() end, desc = "Notification history" }, - { ".", function() Snacks.scratch() end, desc = "Scratch buffer" }, - { "S", function() Snacks.scratch.select() end, desc = "Select scratch buffer" }, - }, - opts = { - terminal = { - win = { style = "terminal", border = "rounded" }, - }, - notifier = { enabled = true, timeout = 3000 }, - scratch = { enabled = true }, - scroll = { enabled = true }, - words = { enabled = true }, - quickfile = { enabled = true }, - }, - }, - - -- ============================================================= - -- Breadcrumbs/Outline: snacks.nvim win - -- ============================================================= - { - "folke/snacks.nvim", - opts = { - win = { - enabled = true, - }, - }, - }, - }, -}) - --- ============================================================= --- LSP Configuration (Neovim 0.11+ API) --- ============================================================= -vim.lsp.enable({ "rust_analyzer", "lua_ls", "ts_ls", "pyright", "clangd", "cssls", "html", "jsonls", "yamlls", "taplo" }) - --- rust-analyzer: 型ヒント有効、リアルタイム診断有効、起動は軽量化 -vim.lsp.config("rust_analyzer", { - settings = { - ["rust-analyzer"] = { - cargo = { allFeatures = true }, - checkOnSave = { command = "clippy" }, - diagnostics = { enable = true, experimental = { enable = true } }, - inlayHints = { - bindingModeHints = { enable = true }, - chainingHints = { enable = true }, - closingBraceHints = { enable = true }, - closureReturnTypeHints = { enable = true }, - lifetimeElisionHints = { enable = true }, - parameterHints = { enable = true }, - typeHints = { enable = true }, - }, - }, - }, -}) - --- lua_ls: Neovim設定用に最適化 -vim.lsp.config("lua_ls", { - settings = { - Lua = { - workspace = { checkThirdParty = false }, - telemetry = { enable = false }, - hint = { enable = true }, - }, - }, -}) - --- TypeScript/JavaScript -vim.lsp.config("ts_ls", { - settings = { - typescript = { inlayHints = { includeInlayParameterNameHints = "all", includeInlayFunctionParameterTypeHints = true } }, - javascript = { inlayHints = { includeInlayParameterNameHints = "all", includeInlayFunctionParameterTypeHints = true } }, - }, -}) - --- Python -vim.lsp.config("pyright", { - settings = { - python = { analysis = { typeCheckingMode = "basic", autoImportCompletions = true } }, - }, -}) - --- ============================================================= --- LSP Keymaps (バッファローカル) --- ============================================================= -vim.api.nvim_create_autocmd("LspAttach", { - group = vim.api.nvim_create_augroup("UserLspConfig", {}), - callback = function(args) - local bufnr = args.buf - local client = vim.lsp.get_client_by_id(args.data.client_id) - local function map(mode, lhs, rhs, desc) - vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, desc = desc }) - end - - -- Navigation - map("n", "gd", vim.lsp.buf.definition, "Goto definition") - map("n", "gD", vim.lsp.buf.declaration, "Goto declaration") - map("n", "gi", vim.lsp.buf.implementation, "Goto implementation") - map("n", "gr", vim.lsp.buf.references, "References") - map("n", "gt", vim.lsp.buf.type_definition, "Goto type definition") - - -- Documentation - map("n", "K", vim.lsp.buf.hover, "Hover") - map("n", "gK", vim.lsp.buf.signature_help, "Signature help") - map("i", "", vim.lsp.buf.signature_help, "Signature help") - - -- Code actions - map({ "n", "v" }, "ca", vim.lsp.buf.code_action, "Code action") - map("n", "cr", vim.lsp.buf.rename, "Rename") - - -- Diagnostics - map("n", "cd", vim.diagnostic.open_float, "Line diagnostics") - map("n", "[d", function() vim.diagnostic.jump({ count = -1, float = true }) end, "Prev diagnostic") - map("n", "]d", function() vim.diagnostic.jump({ count = 1, float = true }) end, "Next diagnostic") - - -- Inlay hints toggle - if client and client.server_capabilities.inlayHintProvider then - map("n", "ih", function() - vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr }) - end, "Toggle inlay hints") - end - - -- Document highlight - if client and client.server_capabilities.documentHighlightProvider then - local group = vim.api.nvim_create_augroup("LspDocumentHighlight", { clear = false }) - vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { - group = group, - buffer = bufnr, - callback = vim.lsp.buf.document_highlight, - }) - vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, { - group = group, - buffer = bufnr, - callback = vim.lsp.buf.clear_references, - }) - end - end, -}) - --- ============================================================= --- Diagnostic Configuration --- ============================================================= -vim.diagnostic.config({ - virtual_text = { prefix = "●", spacing = 4, source = "if_many" }, - signs = { - text = { - [vim.diagnostic.severity.ERROR] = "✘", - [vim.diagnostic.severity.WARN] = "▲", - [vim.diagnostic.severity.INFO] = "ⓘ", - [vim.diagnostic.severity.HINT] = "✶", - }, - }, - underline = true, - update_in_insert = false, - severity_sort = true, - float = { border = "rounded", source = "if_many" }, -}) - --- ============================================================= --- Completion Keymaps --- ============================================================= --- Tab / Shift-Tab / Enter の挿入モード確定系は blink.cmp の keymap 設定に集約する。 --- blink.cmp は InsertEnter でバッファローカルに設定するため、ここで --- グローバルな expr マップを重ねると shadow され、挙動が分かりにくくなる。 --- Tab snippet次 → 候補確定(accept) → 通常Tab --- Shift+Tab snippet前 → 候補を前へ → 通常Shift+Tab --- Enter 候補確定 → 通常の改行 --- C-n/p 候補を次/前 --- C-Space 補完メニューを開く --- C-e 補完メニューを閉じる --- ============================================================= - --- ============================================================= --- Window/Buffer Keymaps (VS Codeライク) --- ============================================================= -local function map(mode, lhs, rhs, desc) - vim.keymap.set(mode, lhs, rhs, { desc = desc }) -end - --- Window (VS Code: Ctrl+W prefix → w) -map("n", "wh", "h", "Window left") -map("n", "wj", "j", "Window down") -map("n", "wk", "k", "Window up") -map("n", "wl", "l", "Window right") -map("n", "wv", "v", "Split vertical") -map("n", "ws", "s", "Split horizontal") -map("n", "wc", "c", "Close window") -map("n", "wo", "o", "Close other windows") -map("n", "w=", "=", "Equalize windows") -map("n", "w|", "|", "Max width") -map("n", "w_", "_", "Max height") - --- Buffer (VS Code: Ctrl+Tab / Ctrl+Shift+Tab) -map("n", "bn", "bnext", "Next buffer") -map("n", "bp", "bprevious", "Prev buffer") -map("n", "bd", "bdelete", "Delete buffer") -map("n", "bD", "bdelete!", "Force delete buffer") -map("n", "bo", "%bdelete|e#", "Delete other buffers") -map("n", "", "bnext", "Next buffer") -map("n", "", "bprevious", "Prev buffer") - --- Tab (VS Code: Ctrl+PgUp/PgDn) -map("n", "tn", "tabnew", "New tab") -map("n", "tc", "tabclose", "Close tab") -map("n", "to", "tabonly", "Close other tabs") -map("n", "]t", "tabnext", "Next tab") -map("n", "[t", "tabprevious", "Prev tab") -map("n", "[T", "tabfirst", "First tab") -map("n", "]T", "tablast", "Last tab") - --- Terminal -map("t", "", "", "Terminal normal mode") -map("t", "", "wincmd h", "Terminal left") -map("t", "", "wincmd j", "Terminal down") -map("t", "", "wincmd k", "Terminal up") -map("t", "", "wincmd l", "Terminal right") - --- ============================================================= --- General Keymaps --- ============================================================= -map("n", "qq", "qa", "Quit all") --- Save: (VS Code style) and fs (file save) -map("n", "", "update", "Save") -map("i", "", "update", "Save") -map("n", "fs", "update", "File save") -map("n", "fS", "wall", "File save all") -map("n", "", "nohlsearch", "Clear search highlight") -map("n", "cl", "nohlsearch", "Clear search highlight") -map("n", "", "nohlsearchdiffupdate", "Clear search + diffupdate") - --- Base.vim keymaps -map("i", "jj", "", "Exit insert mode") -map("i", "", "", "Delete forward") -map("n", "gf", "gF", "Open file under cursor") - --- Better indent (stay in visual mode) -map("v", "<", "", ">gv", "Indent right") - --- Move lines -map("n", "", "m .+1==", "Move line down") -map("n", "", "m .-2==", "Move line up") -map("v", "", ":m '>+1gv=gv", "Move selection down") -map("v", "", ":m '<-2gv=gv", "Move selection up") - --- Quickfix -map("n", "xq", "copen", "Quickfix open") -map("n", "xc", "cclose", "Quickfix close") -map("n", "[q", "cprevious", "Quickfix prev") -map("n", "]q", "cnext", "Quickfix next") - --- Diagnostics list -map("n", "xx", "Telescope diagnostics", "All diagnostics") -map("n", "xb", "Telescope diagnostics bufnr=0", "Buffer diagnostics") - --- ============================================================= --- Cargo (競プロ用) --- ============================================================= -local function cargo_compete(cmd) - if vim.fn.executable("cargo") == 0 then - vim.notify("cargo not found", vim.log.levels.WARN) - return - end - vim.cmd("botright split | terminal cargo compete " .. cmd) - vim.cmd("startinsert") -end - -map("n", "an", function() cargo_compete("new") end, "Cargo compete new") -map("n", "ac", function() cargo_compete("") end, "Cargo compete interactive") -map("n", "at", function() cargo_compete("test") end, "Cargo compete test") -map("n", "as", function() cargo_compete("submit") end, "Cargo compete submit") - --- ============================================================= --- Snippet Management Commands --- ============================================================= -vim.api.nvim_create_user_command("SnippetEdit", function(opts) - local lang = opts.args ~= "" and opts.args or vim.bo.filetype - local snippet_dir = vim.fn.expand("~/.dotfiles/home/snippets") - local file = snippet_dir .. "/" .. lang .. ".json" - if vim.fn.filereadable(file) == 0 then - vim.fn.mkdir(snippet_dir, "p") - vim.fn.writefile({ "{}" }, file) - end - vim.cmd("edit " .. file) -end, { nargs = "?", desc = "Edit snippets for language" }) - -vim.api.nvim_create_user_command("SnippetReload", function() - require("luasnip.loaders.from_vscode").load({ paths = { vim.fn.expand("~/.dotfiles/home/snippets") } }) - require("luasnip.loaders.from_vscode").load({ paths = { vim.fn.expand("~/.local/share/nvim/lazy/friendly-snippets") } }) - vim.notify("Snippets reloaded", vim.log.levels.INFO) -end, { desc = "Reload snippets from dotfiles" }) - --- ============================================================= --- 共通設定読み込み (Vim/Neovim共通) --- ============================================================= -local shared = vim.fn.expand("~/vimfiles/shared/base.vim") +-- Thin Neovim entry point. Windows reads it from %LOCALAPPDATA%\nvim +-- (home/AppData/Local/nvim/init.lua), POSIX from ~/.config/nvim +-- (home/.config/nvim/init.lua); the two files are byte-identical on purpose +-- and source the one canonical config, home/vimfiles/nvim/init.lua, so the +-- configuration is never duplicated across operating systems. +local shared = vim.fn.expand("~/vimfiles/nvim/init.lua") if vim.fn.filereadable(shared) == 1 then vim.cmd.source(shared) -end \ No newline at end of file +else + vim.notify("dotfiles: missing " .. shared .. " (run script/link)", vim.log.levels.WARN) +end diff --git a/home/vimfiles/nvim/init.lua b/home/vimfiles/nvim/init.lua new file mode 100644 index 0000000..872843f --- /dev/null +++ b/home/vimfiles/nvim/init.lua @@ -0,0 +1,826 @@ +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" + +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", + lazypath, + }) +end + +vim.opt.rtp:prepend(lazypath) + +-- 起動時パフォーマンス: 未使用providerを無効化 +vim.g.loaded_perl_provider = 0 +vim.g.loaded_ruby_provider = 0 +vim.g.loaded_node_provider = 0 +vim.g.loaded_python3_provider = 0 + +vim.opt.shadafile = "NONE" +vim.opt.updatetime = 300 +vim.opt.signcolumn = "yes" +vim.opt.lazyredraw = false + +-- リーダーキー +vim.g.mapleader = " " +vim.g.maplocalleader = "\\" + +require("lazy").setup({ + spec = { + -- ============================================================= + -- Core: Treesitter (構文解析・ハイライト・テキストオブジェクト) + -- ============================================================= + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + event = { "BufReadPost", "BufNewFile" }, + cmd = { "TSUpdateSync", "TSInstall", "TSUninstall" }, + opts = { + ensure_installed = { + "bash", + "c", + "cpp", + "css", + "html", + "javascript", + "json", + "jsonc", + "lua", + "markdown", + "markdown_inline", + "python", + "query", + "regex", + "rust", + "toml", + "tsx", + "typescript", + "vim", + "vimdoc", + "yaml", + }, + auto_install = true, + highlight = { enable = true, additional_vim_regex_highlighting = false }, + indent = { enable = true }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "", + node_incremental = "", + scope_incremental = false, + node_decremental = "", + }, + }, + textobjects = { + select = { + enable = true, + lookahead = true, + keymaps = { + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@class.outer", + ["ic"] = "@class.inner", + ["aa"] = "@parameter.outer", + ["ia"] = "@parameter.inner", + }, + }, + move = { + enable = true, + set_jumps = true, + goto_next_start = { ["]f"] = "@function.outer", ["]c"] = "@class.outer" }, + goto_previous_start = { ["[f"] = "@function.outer", ["[c"] = "@class.outer" }, + }, + }, + }, + config = function(_, opts) + require("nvim-treesitter.config").setup(opts) + end, + }, + { + "nvim-treesitter/nvim-treesitter-textobjects", + event = { "BufReadPost", "BufNewFile" }, + }, + + -- ============================================================= + -- File Explorer: oil.nvim (バッファベース、軽量) + -- ============================================================= + { + "stevearc/oil.nvim", + cmd = "Oil", + keys = { + { "e", "Oil", desc = "File explorer" }, + { "E", "Oil .", desc = "File explorer (cwd)" }, + }, + opts = { + default_file_explorer = true, + columns = { "icon", "permissions", "size", "mtime" }, + keymaps = { + ["g?"] = "actions.show_help", + [""] = "actions.select", + [""] = { "actions.select", opts = { vertical = true }, desc = "Open in vertical split" }, + [""] = { "actions.select", opts = { horizontal = true }, desc = "Open in horizontal split" }, + [""] = { "actions.select", opts = { tab = true }, desc = "Open in new tab" }, + [""] = "actions.preview", + [""] = "actions.close", + [""] = "actions.refresh", + ["-"] = "actions.parent", + ["_"] = "actions.open_cwd", + ["`"] = "actions.cd", + ["~"] = { "actions.cd", opts = { scope = "tab" }, desc = "cd to home" }, + ["gs"] = "actions.change_sort", + ["gx"] = "actions.open_external", + ["g."] = "actions.toggle_hidden", + ["g\\"] = "actions.toggle_trash", + }, + view_options = { + show_hidden = true, + is_always_hidden = function(name, _) + return name == ".." or name == ".git" + end, + }, + float = { + padding = 2, + max_width = 0.8, + max_height = 0.8, + border = "rounded", + }, + }, + }, + + -- ============================================================= + -- Completion: blink.cmp (高速、LSP統合) + -- ============================================================= + { + "saghen/blink.cmp", + version = "1.*", + dependencies = { + "L3MON4D3/LuaSnip", + "rafamadriz/friendly-snippets", + }, + event = { "BufReadPost", "BufNewFile" }, + opts = { + keymap = { + preset = "none", + [""] = { "select_next", "fallback" }, + [""] = { "select_prev", "fallback" }, + [""] = { "show", "fallback" }, + [""] = { "hide", "fallback" }, + [""] = { "scroll_documentation_down", "fallback" }, + [""] = { "scroll_documentation_up", "fallback" }, + [""] = { "select_and_accept" }, + -- Tab: snippet次 → 候補確定(選択済みをaccept、未選択なら先頭をaccept) → 通常Tab + [""] = { "snippet_forward", "select_and_accept", "fallback" }, + -- Shift+Tab: snippet前 → 候補を前へ → 通常Shift+Tab + [""] = { "snippet_backward", "select_prev", "fallback" }, + [""] = { "accept", "fallback" }, + }, + cmdline = { + enabled = true, + keymap = { + preset = "inherit", + [""] = { "show_and_insert", "select_next" }, + [""] = { "show_and_insert", "select_prev" }, + }, + }, + completion = { + documentation = { + auto_show = true, + auto_show_delay_ms = 200, + window = { border = "rounded" }, + }, + menu = { + border = "rounded", + draw = { + columns = { + { "kind_icon", "label", "label_description", gap = 1 }, + { "source_name" }, + }, + }, + }, + ghost_text = { enabled = true }, + }, + signature = { + enabled = true, + window = { border = "rounded" }, + }, + sources = { + default = { "lsp", "path", "snippets", "buffer" }, + providers = { + snippets = { + name = "snippets", + module = "blink.cmp.sources.snippets", + score_offset = 4, + }, + }, + }, + snippets = { preset = "luasnip" }, + }, + config = function(_, opts) + require("blink.cmp").setup(opts) + end, + }, + + -- ============================================================= + -- Snippets: LuaSnip (VS Code形式対応、高機能) + -- ============================================================= + { + "L3MON4D3/LuaSnip", + version = "v2.*", + build = "make install_jsregexp", + event = { "BufReadPost", "BufNewFile" }, + dependencies = { + "rafamadriz/friendly-snippets", + }, + opts = { + history = true, + delete_check_events = "TextChanged", + enable_autosnippets = true, + }, + config = function(_, opts) + require("luasnip").setup(opts) + -- ドットファイル管理のスニペットディレクトリを読み込み + local snippet_dir = vim.fn.expand("~/.dotfiles/home/snippets") + if vim.fn.isdirectory(snippet_dir) == 1 then + require("luasnip.loaders.from_vscode").load({ paths = { snippet_dir } }) + end + -- friendly-snippetsも読み込み (package.jsonがルートにあるため明示的なパス指定が必要) + local friendly_dir = vim.fn.expand("~/.local/share/nvim/lazy/friendly-snippets") + if vim.fn.isdirectory(friendly_dir) == 1 then + require("luasnip.loaders.from_vscode").load({ paths = { friendly_dir } }) + end + end, + }, + + -- ============================================================= + -- Git: gitsigns.nvim (サイン表示) + diffview.nvim (差分表示) + -- ============================================================= + { + "lewis6991/gitsigns.nvim", + event = { "BufReadPost", "BufNewFile" }, + opts = { + signs = { + add = { text = "▎" }, + change = { text = "▎" }, + delete = { text = "" }, + topdelete = { text = "" }, + changedelete = { text = "▎" }, + untracked = { text = "▎" }, + }, + signcolumn = true, + numhl = false, + linehl = false, + word_diff = false, + watch_gitdir = { interval = 1000, follow_files = true }, + attach_to_untracked = true, + current_line_blame = false, + current_line_blame_opts = { virt_text = true, virt_text_pos = "eol", delay = 500 }, + preview_config = { border = "rounded" }, + on_attach = function(bufnr) + local gs = package.loaded.gitsigns + local function map(mode, l, r, desc) + vim.keymap.set(mode, l, r, { buffer = bufnr, desc = desc }) + end + map("n", "]h", gs.next_hunk, "Next hunk") + map("n", "[h", gs.prev_hunk, "Prev hunk") + map("n", "hs", gs.stage_hunk, "Stage hunk") + map("n", "hr", gs.reset_hunk, "Reset hunk") + map("n", "hS", gs.stage_buffer, "Stage buffer") + map("n", "hu", gs.undo_stage_hunk, "Undo stage hunk") + map("n", "hp", gs.preview_hunk, "Preview hunk") + map("n", "hb", function() gs.blame_line({ full = true }) end, "Blame line") + map("n", "hd", gs.diffthis, "Diff this") + map("n", "hD", function() gs.diffthis("~") end, "Diff this ~") + map("n", "tb", gs.toggle_current_line_blame, "Toggle blame line") + map("n", "td", gs.toggle_deleted, "Toggle deleted") + end, + }, + }, + { + "sindrets/diffview.nvim", + cmd = { "DiffviewOpen", "DiffviewClose", "DiffviewFileHistory" }, + keys = { + { "gd", "DiffviewOpen", desc = "Git diff view" }, + { "gD", "DiffviewClose", desc = "Close diff view" }, + { "gh", "DiffviewFileHistory", desc = "Git file history" }, + }, + opts = { + enhanced_diff_hl = true, + view = { + default = { winbar_info = true }, + merge_tool = { layout = "diff3_mixed" }, + }, + }, + }, + + -- ============================================================= + -- Search: telescope.nvim (ファイル・全文検索) + -- ============================================================= + { + "nvim-telescope/telescope.nvim", + cmd = "Telescope", + keys = { + { "ff", "Telescope find_files", desc = "Find files" }, + { "fg", "Telescope live_grep", desc = "Live grep" }, + { "fb", "Telescope buffers", desc = "Buffers" }, + { "fh", "Telescope help_tags", desc = "Help tags" }, + { "fs", "Telescope lsp_document_symbols", desc = "Document symbols" }, + { "fS", "Telescope lsp_workspace_symbols", desc = "Workspace symbols" }, + { "fr", "Telescope lsp_references", desc = "References" }, + { "fd", "Telescope diagnostics", desc = "Diagnostics" }, + { "fk", "Telescope keymaps", desc = "Keymaps" }, + { "fc", "Telescope commands", desc = "Commands" }, + { "fm", "Telescope marks", desc = "Marks" }, + { "fo", "Telescope oldfiles", desc = "Recent files" }, + }, + dependencies = { + "nvim-lua/plenary.nvim", + { "nvim-telescope/telescope-fzf-native.nvim", build = "make" }, + }, + opts = { + defaults = { + prompt_prefix = " ", + selection_caret = " ", + border = "rounded", + sorting_strategy = "ascending", + layout_config = { + horizontal = { prompt_position = "top", preview_width = 0.55 }, + vertical = { mirror = false }, + width = 0.87, + height = 0.80, + }, + mappings = { + i = { + [""] = "move_selection_next", + [""] = "move_selection_previous", + [""] = "send_to_qflist", + [""] = "send_selected_to_qflist", + }, + }, + }, + pickers = { + find_files = { hidden = true, follow = true }, + buffers = { sort_lastused = true, ignore_current_buffer = true }, + }, + }, + config = function(_, opts) + require("telescope").setup(opts) + pcall(require("telescope").load_extension, "fzf") + end, + }, + + -- ============================================================= + -- Formatter: conform.nvim (保存時フォーマット) + -- ============================================================= + { + "stevearc/conform.nvim", + event = { "BufWritePre" }, + cmd = { "ConformInfo" }, + keys = { + { "cf", function() require("conform").format({ async = true, lsp_format = "fallback" }) end, desc = "Format buffer" }, + }, + opts = { + format_on_save = { timeout_ms = 1000, lsp_format = "fallback" }, + formatters_by_ft = { + rust = { "rustfmt" }, + lua = { "stylua" }, + python = { "ruff_format" }, + javascript = { "prettier" }, + typescript = { "prettier" }, + javascriptreact = { "prettier" }, + typescriptreact = { "prettier" }, + json = { "prettier" }, + jsonc = { "prettier" }, + css = { "prettier" }, + html = { "prettier" }, + markdown = { "prettier" }, + yaml = { "prettier" }, + toml = { "taplo" }, + sh = { "shfmt" }, + c = { "clang_format" }, + cpp = { "clang_format" }, + }, + }, + }, + + -- ============================================================= + -- LSP: nvim-lspconfig + mason.nvim + -- ============================================================= + { + "mason-org/mason.nvim", + cmd = { "Mason", "MasonInstall", "MasonUninstall", "MasonUpdate" }, + keys = { { "mi", "Mason", desc = "Mason" } }, + opts = {}, + }, + { + "neovim/nvim-lspconfig", + event = { "BufReadPost", "BufNewFile" }, + dependencies = { "mason-org/mason.nvim" }, + }, + + -- ============================================================= + -- UI: which-key.nvim (キーマップガイド) + -- ============================================================= + { + "folke/which-key.nvim", + event = "VeryLazy", + opts = { + preset = "modern", + delay = 300, + icons = { mappings = true, rules = {} }, + spec = { + { "f", group = "Find/Search" }, + { "g", group = "Git" }, + { "h", group = "Git Hunk" }, + { "c", group = "Code/Format" }, + { "l", group = "LSP" }, + { "t", group = "Toggle/Terminal" }, + { "w", group = "Window" }, + { "b", group = "Buffer" }, + { "x", group = "Diagnostics" }, + { "a", group = "Cargo/Action" }, + { "g", group = "Goto" }, + { "[", group = "Prev" }, + { "]", group = "Next" }, + }, + }, + }, + + -- ============================================================= + -- UI: mini.nvim (statusline, pairs, etc.) + -- ============================================================= + { + "echasnovski/mini.nvim", + version = "*", + event = { "BufReadPost", "BufNewFile" }, + config = function() + -- mini.pairs: 自動括弧補完 + require("mini.pairs").setup({ + modes = { insert = true, command = false, terminal = false }, + }) + + -- mini.statusline: ステータスライン + require("mini.statusline").setup({ + use_icons = vim.g.have_nerd_font, + content = { + active = function() + local mode, mode_hl = MiniStatusline.section_mode({ trunc_width = 120 }) + local git = MiniStatusline.section_git({ trunc_width = 40 }) + local diff = MiniStatusline.section_diff({ trunc_width = 75 }) + local diagnostics = MiniStatusline.section_diagnostics({ trunc_width = 75 }) + local filename = MiniStatusline.section_filename({ trunc_width = 140 }) + local fileinfo = MiniStatusline.section_fileinfo({ trunc_width = 120 }) + local location = MiniStatusline.section_location({ trunc_width = 75 }) + local search = MiniStatusline.section_searchcount({ trunc_width = 75 }) + + return MiniStatusline.combine_groups({ + { hl = mode_hl, strings = { mode } }, + { hl = "MiniStatuslineDevinfo", strings = { git, diff, diagnostics } }, + "%<", + { hl = "MiniStatuslineFilename", strings = { filename } }, + "%=", + { hl = "MiniStatuslineFileinfo", strings = { fileinfo } }, + { hl = mode_hl, strings = { location, search } }, + }) + end, + }, + }) + + -- mini.icons: アイコン + require("mini.icons").setup() + + -- mini.ai: テキストオブジェクト拡張 + require("mini.ai").setup({ + custom_textobjects = { + f = require("mini.ai").gen_spec.treesitter({ a = "@function.outer", i = "@function.inner" }), + c = require("mini.ai").gen_spec.treesitter({ a = "@class.outer", i = "@class.inner" }), + }, + }) + + -- mini.surround: 囲み操作 + require("mini.surround").setup({ + mappings = { + add = "gsa", + delete = "gsd", + find = "gsf", + find_left = "gsF", + highlight = "gsh", + replace = "gsr", + update_n_lines = "gsn", + }, + }) + end, + }, + + -- ============================================================= + -- Terminal & UI: snacks.nvim (ターミナル、ピッカー、通知等) + -- ============================================================= + { + "folke/snacks.nvim", + priority = 1000, + lazy = false, + keys = { + { "tt", function() Snacks.terminal.toggle() end, desc = "Toggle terminal" }, + { "tf", function() Snacks.terminal.toggle(nil, { win = { position = "float" } }) end, desc = "Float terminal" }, + { "tb", function() Snacks.terminal.toggle(nil, { win = { position = "bottom" } }) end, desc = "Bottom terminal" }, + { "tr", function() Snacks.terminal.toggle("lazygit") end, desc = "Lazygit" }, + { "tn", function() Snacks.notifier.show_history() end, desc = "Notification history" }, + { ".", function() Snacks.scratch() end, desc = "Scratch buffer" }, + { "S", function() Snacks.scratch.select() end, desc = "Select scratch buffer" }, + }, + opts = { + terminal = { + win = { style = "terminal", border = "rounded" }, + }, + notifier = { enabled = true, timeout = 3000 }, + scratch = { enabled = true }, + scroll = { enabled = true }, + words = { enabled = true }, + quickfile = { enabled = true }, + }, + }, + + -- ============================================================= + -- Breadcrumbs/Outline: snacks.nvim win + -- ============================================================= + { + "folke/snacks.nvim", + opts = { + win = { + enabled = true, + }, + }, + }, + }, +}) + +-- ============================================================= +-- LSP Configuration (Neovim 0.11+ API) +-- ============================================================= +vim.lsp.enable({ "rust_analyzer", "lua_ls", "ts_ls", "pyright", "clangd", "cssls", "html", "jsonls", "yamlls", "taplo" }) + +-- rust-analyzer: 型ヒント有効、リアルタイム診断有効、起動は軽量化 +vim.lsp.config("rust_analyzer", { + settings = { + ["rust-analyzer"] = { + cargo = { allFeatures = true }, + checkOnSave = { command = "clippy" }, + diagnostics = { enable = true, experimental = { enable = true } }, + inlayHints = { + bindingModeHints = { enable = true }, + chainingHints = { enable = true }, + closingBraceHints = { enable = true }, + closureReturnTypeHints = { enable = true }, + lifetimeElisionHints = { enable = true }, + parameterHints = { enable = true }, + typeHints = { enable = true }, + }, + }, + }, +}) + +-- lua_ls: Neovim設定用に最適化 +vim.lsp.config("lua_ls", { + settings = { + Lua = { + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, + hint = { enable = true }, + }, + }, +}) + +-- TypeScript/JavaScript +vim.lsp.config("ts_ls", { + settings = { + typescript = { inlayHints = { includeInlayParameterNameHints = "all", includeInlayFunctionParameterTypeHints = true } }, + javascript = { inlayHints = { includeInlayParameterNameHints = "all", includeInlayFunctionParameterTypeHints = true } }, + }, +}) + +-- Python +vim.lsp.config("pyright", { + settings = { + python = { analysis = { typeCheckingMode = "basic", autoImportCompletions = true } }, + }, +}) + +-- ============================================================= +-- LSP Keymaps (バッファローカル) +-- ============================================================= +vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("UserLspConfig", {}), + callback = function(args) + local bufnr = args.buf + local client = vim.lsp.get_client_by_id(args.data.client_id) + local function map(mode, lhs, rhs, desc) + vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, desc = desc }) + end + + -- Navigation + map("n", "gd", vim.lsp.buf.definition, "Goto definition") + map("n", "gD", vim.lsp.buf.declaration, "Goto declaration") + map("n", "gi", vim.lsp.buf.implementation, "Goto implementation") + map("n", "gr", vim.lsp.buf.references, "References") + map("n", "gt", vim.lsp.buf.type_definition, "Goto type definition") + + -- Documentation + map("n", "K", vim.lsp.buf.hover, "Hover") + map("n", "gK", vim.lsp.buf.signature_help, "Signature help") + map("i", "", vim.lsp.buf.signature_help, "Signature help") + + -- Code actions + map({ "n", "v" }, "ca", vim.lsp.buf.code_action, "Code action") + map("n", "cr", vim.lsp.buf.rename, "Rename") + + -- Diagnostics + map("n", "cd", vim.diagnostic.open_float, "Line diagnostics") + map("n", "[d", function() vim.diagnostic.jump({ count = -1, float = true }) end, "Prev diagnostic") + map("n", "]d", function() vim.diagnostic.jump({ count = 1, float = true }) end, "Next diagnostic") + + -- Inlay hints toggle + if client and client.server_capabilities.inlayHintProvider then + map("n", "ih", function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr }) + end, "Toggle inlay hints") + end + + -- Document highlight + if client and client.server_capabilities.documentHighlightProvider then + local group = vim.api.nvim_create_augroup("LspDocumentHighlight", { clear = false }) + vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { + group = group, + buffer = bufnr, + callback = vim.lsp.buf.document_highlight, + }) + vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, { + group = group, + buffer = bufnr, + callback = vim.lsp.buf.clear_references, + }) + end + end, +}) + +-- ============================================================= +-- Diagnostic Configuration +-- ============================================================= +vim.diagnostic.config({ + virtual_text = { prefix = "●", spacing = 4, source = "if_many" }, + signs = { + text = { + [vim.diagnostic.severity.ERROR] = "✘", + [vim.diagnostic.severity.WARN] = "▲", + [vim.diagnostic.severity.INFO] = "ⓘ", + [vim.diagnostic.severity.HINT] = "✶", + }, + }, + underline = true, + update_in_insert = false, + severity_sort = true, + float = { border = "rounded", source = "if_many" }, +}) + +-- ============================================================= +-- Completion Keymaps +-- ============================================================= +-- Tab / Shift-Tab / Enter の挿入モード確定系は blink.cmp の keymap 設定に集約する。 +-- blink.cmp は InsertEnter でバッファローカルに設定するため、ここで +-- グローバルな expr マップを重ねると shadow され、挙動が分かりにくくなる。 +-- Tab snippet次 → 候補確定(accept) → 通常Tab +-- Shift+Tab snippet前 → 候補を前へ → 通常Shift+Tab +-- Enter 候補確定 → 通常の改行 +-- C-n/p 候補を次/前 +-- C-Space 補完メニューを開く +-- C-e 補完メニューを閉じる +-- ============================================================= + +-- ============================================================= +-- Window/Buffer Keymaps (VS Codeライク) +-- ============================================================= +local function map(mode, lhs, rhs, desc) + vim.keymap.set(mode, lhs, rhs, { desc = desc }) +end + +-- Window (VS Code: Ctrl+W prefix → w) +map("n", "wh", "h", "Window left") +map("n", "wj", "j", "Window down") +map("n", "wk", "k", "Window up") +map("n", "wl", "l", "Window right") +map("n", "wv", "v", "Split vertical") +map("n", "ws", "s", "Split horizontal") +map("n", "wc", "c", "Close window") +map("n", "wo", "o", "Close other windows") +map("n", "w=", "=", "Equalize windows") +map("n", "w|", "|", "Max width") +map("n", "w_", "_", "Max height") + +-- Buffer (VS Code: Ctrl+Tab / Ctrl+Shift+Tab) +map("n", "bn", "bnext", "Next buffer") +map("n", "bp", "bprevious", "Prev buffer") +map("n", "bd", "bdelete", "Delete buffer") +map("n", "bD", "bdelete!", "Force delete buffer") +map("n", "bo", "%bdelete|e#", "Delete other buffers") +map("n", "", "bnext", "Next buffer") +map("n", "", "bprevious", "Prev buffer") + +-- Tab (VS Code: Ctrl+PgUp/PgDn) +map("n", "tn", "tabnew", "New tab") +map("n", "tc", "tabclose", "Close tab") +map("n", "to", "tabonly", "Close other tabs") +map("n", "]t", "tabnext", "Next tab") +map("n", "[t", "tabprevious", "Prev tab") +map("n", "[T", "tabfirst", "First tab") +map("n", "]T", "tablast", "Last tab") + +-- Terminal +map("t", "", "", "Terminal normal mode") +map("t", "", "wincmd h", "Terminal left") +map("t", "", "wincmd j", "Terminal down") +map("t", "", "wincmd k", "Terminal up") +map("t", "", "wincmd l", "Terminal right") + +-- ============================================================= +-- General Keymaps +-- ============================================================= +map("n", "qq", "qa", "Quit all") +-- Save: (VS Code style) and fs (file save) +map("n", "", "update", "Save") +map("i", "", "update", "Save") +map("n", "fs", "update", "File save") +map("n", "fS", "wall", "File save all") +map("n", "", "nohlsearch", "Clear search highlight") +map("n", "cl", "nohlsearch", "Clear search highlight") +map("n", "", "nohlsearchdiffupdate", "Clear search + diffupdate") + +-- Base.vim keymaps +map("i", "jj", "", "Exit insert mode") +map("i", "", "", "Delete forward") +map("n", "gf", "gF", "Open file under cursor") + +-- Better indent (stay in visual mode) +map("v", "<", "", ">gv", "Indent right") + +-- Move lines +map("n", "", "m .+1==", "Move line down") +map("n", "", "m .-2==", "Move line up") +map("v", "", ":m '>+1gv=gv", "Move selection down") +map("v", "", ":m '<-2gv=gv", "Move selection up") + +-- Quickfix +map("n", "xq", "copen", "Quickfix open") +map("n", "xc", "cclose", "Quickfix close") +map("n", "[q", "cprevious", "Quickfix prev") +map("n", "]q", "cnext", "Quickfix next") + +-- Diagnostics list +map("n", "xx", "Telescope diagnostics", "All diagnostics") +map("n", "xb", "Telescope diagnostics bufnr=0", "Buffer diagnostics") + +-- ============================================================= +-- Cargo (競プロ用) +-- ============================================================= +local function cargo_compete(cmd) + if vim.fn.executable("cargo") == 0 then + vim.notify("cargo not found", vim.log.levels.WARN) + return + end + vim.cmd("botright split | terminal cargo compete " .. cmd) + vim.cmd("startinsert") +end + +map("n", "an", function() cargo_compete("new") end, "Cargo compete new") +map("n", "ac", function() cargo_compete("") end, "Cargo compete interactive") +map("n", "at", function() cargo_compete("test") end, "Cargo compete test") +map("n", "as", function() cargo_compete("submit") end, "Cargo compete submit") + +-- ============================================================= +-- Snippet Management Commands +-- ============================================================= +vim.api.nvim_create_user_command("SnippetEdit", function(opts) + local lang = opts.args ~= "" and opts.args or vim.bo.filetype + local snippet_dir = vim.fn.expand("~/.dotfiles/home/snippets") + local file = snippet_dir .. "/" .. lang .. ".json" + if vim.fn.filereadable(file) == 0 then + vim.fn.mkdir(snippet_dir, "p") + vim.fn.writefile({ "{}" }, file) + end + vim.cmd("edit " .. file) +end, { nargs = "?", desc = "Edit snippets for language" }) + +vim.api.nvim_create_user_command("SnippetReload", function() + require("luasnip.loaders.from_vscode").load({ paths = { vim.fn.expand("~/.dotfiles/home/snippets") } }) + require("luasnip.loaders.from_vscode").load({ paths = { vim.fn.expand("~/.local/share/nvim/lazy/friendly-snippets") } }) + vim.notify("Snippets reloaded", vim.log.levels.INFO) +end, { desc = "Reload snippets from dotfiles" }) + +-- ============================================================= +-- 共通設定読み込み (Vim/Neovim共通) +-- ============================================================= +local shared = vim.fn.expand("~/vimfiles/shared/base.vim") +if vim.fn.filereadable(shared) == 1 then + vim.cmd.source(shared) +end \ No newline at end of file diff --git a/script/lib/managed-targets.sh b/script/lib/managed-targets.sh index 28adb22..2fb227e 100644 --- a/script/lib/managed-targets.sh +++ b/script/lib/managed-targets.sh @@ -21,6 +21,16 @@ managed_is_composer_owned() { return 1 } +# home/AppData mirrors %LOCALAPPDATA% for Windows-native editors. POSIX link/check +# must never create ~/AppData; the Windows adapter (script/link.ps1) owns those +# entries. Skipped sources are never deleted, so an older POSIX link stays put. +managed_is_platform_owned() { + case "$1" in + AppData/*) return 0 ;; + esac + return 1 +} + # Top-level unit names discovered by managed_sources; matched exactly, never # word-split or substring-matched (names may contain spaces). MANAGED_UNIT_NAMES=() @@ -75,6 +85,7 @@ managed_sources() { first="${relative%%/*}" managed_is_unit_name "$first" && continue managed_is_composer_owned "$relative" && continue + managed_is_platform_owned "$relative" && continue printf '%s\0' "$source" done < <(find "$source_root" \( -type f -o -type l \) -print0) } diff --git a/script/link.ps1 b/script/link.ps1 index e0548e7..ed95166 100644 --- a/script/link.ps1 +++ b/script/link.ps1 @@ -41,6 +41,8 @@ $PosixOnly = @{ '.local/bin/devices' = 'POSIX launcher; on Windows use script/devices.ps1' '.local/bin/agent' = 'POSIX symlink to agent.ts; on Windows use script/agent.ps1 and `agent shortcuts create`' '.claude/statusline-command.sh' = 'bash status line renderer; not wired for Windows-native Claude Code' + '.vimrc' = 'POSIX Vim entry point; Windows uses %LOCALAPPDATA%\Programs\Vim\_vimrc' + '.config/nvim/init.lua' = 'POSIX Neovim entry point; Windows uses %LOCALAPPDATA%\nvim\init.lua' } $SourceRoot = Join-Path $RepoRoot 'home'