Neovim 系列(八):語法高亮與檔案導航——Treesitter + Telescope

這是 Neovim 從零開始系列的第八篇。整個系列共 12 篇文章,將帶你從完全不懂 Vim,到能用 Neovim 打造一個完整的現代化開發環境。 本篇的目標 經過前幾篇的設定,你的 Neovim 已經有了 LSP 和自動補全。這篇要加入三個讓開發體驗再度提升的功能: Treesitter:基於語法樹的精確高亮和文字操作 Telescope:強大的模糊搜尋(取代 VSCode 的 Cmd+P) oil.nvim:檔案瀏覽器(取代 VSCode 的左側邊欄) Treesitter:真正理解你的程式碼 傳統語法高亮 vs Treesitter 傳統的語法高亮用正則表達式來匹配——它只看文字模式,不懂程式碼結構。這導致: 複雜的語法可能標錯顏色 巢狀結構容易混亂 不同語言嵌套(如 HTML 中的 JavaScript)效果差 Treesitter 完全不同——它解析程式碼為語法樹(AST),真正理解程式碼的結構。好處是: 語法高亮更精確(區分函數名、變數、型別、常數等) 支援增量解析(編輯時只重新解析修改的部分,非常快) 提供基於語法結構的文字操作(如選取整個函數) 安裝 Treesitter -- lua/plugins/treesitter.lua return { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate", event = "BufReadPost", dependencies = { "nvim-treesitter/nvim-treesitter-textobjects", }, config = function() require("nvim-treesitter.configs").setup({ ensure_installed = { "lua", "vim", "vimdoc", "javascript", "typescript", "tsx", "go", "gomod", "gosum", "python", "html", "css", "json", "yaml", "toml", "markdown", "markdown_inline", "bash", "dockerfile", "gitcommit", "diff", }, auto_install = true, highlight = { enable = true, }, indent = { enable = true, }, incremental_selection = { enable = true, keymaps = { init_selection = "<C-space>", node_incremental = "<C-space>", scope_incremental = false, node_decremental = "<bs>", }, }, }) end, } 增量選取 上面設定中的 incremental_selection 是一個非常好用的功能: ...

2026年3月2日 · 5 min · 956 words · Jack

遊戲巨頭的雲端征途:AWS 架構實戰案例分析

前言 理論需要實踐驗證。本文精選了全球知名遊戲公司的 AWS 架構案例,深入分析他們如何應用 Well-Architected Framework 的原則,克服技術挑戰,打造出服務億萬玩家的遊戲平台。 案例一:Epic Games - Fortnite 的規模奇蹟 挑戰 同時在線玩家峰值:1,250 萬 每日活躍用戶:7,830 萬 全球延遲要求:< 30ms 版本更新頻率:每 2 週 架構亮點 class FortniteArchitecture: def __init__(self): self.regions = 23 self.dedicated_servers = 125000 self.daily_data_processed = "92PB" def scaling_strategy(self): return { 'predictive_scaling': { 'ml_model': 'LSTM + Prophet', 'accuracy': 0.92, 'prediction_window': '6_hours' }, 'instance_mix': { 'on_demand': '20%', 'reserved': '30%', 'spot': '50%' }, 'global_distribution': { 'regions': self.regions, 'edge_locations': 200, 'anycast_network': True } } 關鍵成功因素 預測性擴展:基於機器學習預測玩家行為 全球部署:23 個區域確保低延遲 混合雲策略:AWS + 自建資料中心 創新技術:Unreal Engine + AWS 深度整合 成果 支撐史上最大規模虛擬演唱會(1,230 萬同時觀看) 99.99% 可用性 平均延遲 25ms 案例二:Riot Games - 英雄聯盟的全球征戰 挑戰 月活躍用戶:1.5 億 同時進行比賽:300 萬場 電競賽事直播:4,000 萬觀眾 全球一致性要求:極高 技術架構 架構特色: Riot Direct: 描述: 專用網路基礎設施 覆蓋: 全球 70% 玩家 效果: - 延遲降低: 30% - 封包遺失減少: 60% 分片架構: 每區域分片數: 10 每分片玩家數: 100000 故障隔離: 完全隔離 遊戲服務: matchmaking: 服務: AWS Lambda + DynamoDB 配對時間: < 30 秒 replay_system: 存儲: S3 + CloudFront 容量: 500TB/月 chat_service: 技術: WebSocket + API Gateway 同時連接: 1000 萬 成果 全球平均延遲:35ms 服務可用性:99.995% 成本優化:較傳統架構節省 40% 案例三:Supercell - 移動遊戲的無伺服器革命 遊戲組合 Clash of Clans Clash Royale Brawl Stars Hay Day 無伺服器架構 class SupercellServerless: def architecture_components(self): return { 'compute': { 'primary': 'AWS Lambda', 'container': 'Fargate', 'batch': 'AWS Batch' }, 'database': { 'player_data': 'DynamoDB', 'leaderboard': 'ElastiCache', 'analytics': 'Redshift' }, 'messaging': { 'real_time': 'API Gateway WebSocket', 'push_notifications': 'SNS', 'event_bus': 'EventBridge' }, 'benefits': { 'cost_reduction': '60%', 'deployment_time': '5_minutes', 'scaling': 'automatic', 'maintenance': 'minimal' } } 成果 開發速度提升 300% 營運成本降低 60% 零停機部署 支援 2.5 億月活躍用戶 案例四:Roblox - 元宇宙平台的技術基石 規模 日活躍用戶:7,000 萬 同時在線體驗:4,000 萬個 開發者數量:900 萬 月交易量:10 億美元 混合雲架構 基礎設施: 計算層: AWS: 60% 私有雲: 40% 存儲層: 用戶生成內容: S3 (500PB) 遊戲狀態: DynamoDB Global Tables 分析數據: Redshift (100PB) 網路層: CDN: CloudFront + 自建 加速: Global Accelerator 專線: Direct Connect 10Gbps x 4 創新技術: 物理引擎: - GPU 加速運算 - 分散式物理模擬 內容審核: - Amazon Rekognition - Amazon Comprehend - 自訓練 ML 模型 成果 支援百萬創作者生態 99.9% 平台可用性 內容審核準確率 98% 案例五:PUBG - 大逃殺遊戲的極限挑戰 技術挑戰 100 名玩家同場競技 8km x 8km 超大地圖 即時物理模擬 全球同步要求 解決方案 class PUBGArchitecture: def optimization_techniques(self): return { 'network': { 'tick_rate': 60, 'netcode': 'client_side_prediction', 'compression': 'delta_compression', 'protocol': 'custom_udp' }, 'server': { 'instance_type': 'c5n.24xlarge', 'cpu_cores': 96, 'network': '100Gbps', 'region_count': 15 }, 'data_sync': { 'method': 'eventual_consistency', 'conflict_resolution': 'server_authoritative', 'state_snapshot': 'every_100ms' } } 成果 支援 300 萬同時在線 平均配對時間 < 10 秒 作弊檢測率提升 95% 經驗總結 共同成功模式 彈性優先 ...

2025年9月22日 · 3 min · 460 words · Jack

Neovim 系列(九):Git 整合工作流——在編輯器中完成所有 Git 操作

這是 Neovim 從零開始系列的第九篇。整個系列共 12 篇文章,將帶你從完全不懂 Vim,到能用 Neovim 打造一個完整的現代化開發環境。 為什麼在 Neovim 中操作 Git? VSCode 有內建的 Source Control 面板和 GitLens 擴充,讓你不用離開編輯器就能操作 Git。在 Neovim 中,我們要用幾個 plugins 達到同樣甚至更好的體驗: gitsigns.nvim:在行號旁顯示 Git 變更狀態 lazygit:功能強大的 Terminal Git UI diffview.nvim:在 Neovim 中查看 diff gitsigns.nvim:行內 Git 狀態 gitsigns 是最基本也最必要的 Git plugin。它在 sign column(行號左邊)顯示每一行的 Git 狀態: │ 綠色:新增的行 │ 藍色:修改的行 _ 紅色:刪除的行 -- lua/plugins/gitsigns.lua return { "lewis6991/gitsigns.nvim", event = "BufReadPost", config = function() require("gitsigns").setup({ signs = { add = { text = "│" }, change = { text = "│" }, delete = { text = "_" }, topdelete = { text = "‾" }, changedelete = { text = "~" }, }, on_attach = function(bufnr) local gs = package.loaded.gitsigns local opts = { buffer = bufnr } -- 導航:在 hunk(變更區塊)之間跳轉 vim.keymap.set("n", "]h", gs.next_hunk, opts) vim.keymap.set("n", "[h", gs.prev_hunk, opts) -- Stage / Unstage vim.keymap.set("n", "<leader>hs", gs.stage_hunk, opts) vim.keymap.set("n", "<leader>hr", gs.reset_hunk, opts) vim.keymap.set("v", "<leader>hs", function() gs.stage_hunk({ vim.fn.line("."), vim.fn.line("v") }) end, opts) vim.keymap.set("v", "<leader>hr", function() gs.reset_hunk({ vim.fn.line("."), vim.fn.line("v") }) end, opts) -- Stage / Reset 整個 buffer vim.keymap.set("n", "<leader>hS", gs.stage_buffer, opts) vim.keymap.set("n", "<leader>hR", gs.reset_buffer, opts) -- Undo stage vim.keymap.set("n", "<leader>hu", gs.undo_stage_hunk, opts) -- Preview hunk vim.keymap.set("n", "<leader>hp", gs.preview_hunk, opts) -- Blame vim.keymap.set("n", "<leader>hb", function() gs.blame_line({ full = true }) end, opts) vim.keymap.set("n", "<leader>tb", gs.toggle_current_line_blame, opts) -- Diff vim.keymap.set("n", "<leader>hd", gs.diffthis, opts) end, }) end, } gitsigns 快捷鍵總覽 快捷鍵 功能 說明 ]h / [h 下/上一個 hunk 在變更區塊間跳轉 <leader>hs Stage hunk 暫存當前變更區塊 <leader>hr Reset hunk 撤銷當前變更區塊 <leader>hS Stage buffer 暫存整個檔案 <leader>hR Reset buffer 撤銷整個檔案的變更 <leader>hu Undo stage 取消暫存 <leader>hp Preview hunk 預覽變更內容 <leader>hb Blame line 顯示當前行的 Git blame <leader>tb Toggle blame 切換行內 blame 顯示 <leader>hd Diff this 查看當前檔案的 diff 日常使用流程 1. 編輯程式碼(sign column 自動顯示變更標記) 2. 用 ]h / [h 在變更區塊間跳轉,檢查修改內容 3. 用 <leader>hp 預覽 hunk,確認要保留的變更 4. 用 <leader>hs stage 個別 hunk(或 <leader>hS stage 整個檔案) 5. 用 <leader>hr 撤銷不需要的變更 這種 hunk 級別的 staging 比 VSCode 的整個檔案 stage 更精細。你可以只 stage 一個檔案中的部分修改。 ...

2026年3月3日 · 4 min · 844 words · Jack

Neovim 系列(十):Terminal 與 Claude Code 整合——AI 時代的開發工作流

這是 Neovim 從零開始系列的第十篇。整個系列共 12 篇文章,將帶你從完全不懂 Vim,到能用 Neovim 打造一個完整的現代化開發環境。 Terminal 工作流的魅力 這是我當初想從 VSCode 轉到 Neovim 的核心原因之一:讓整個開發流程都在 terminal 中完成。 想像一下這樣的畫面: ┌──────────────────────────────────────┐ │ tmux session: my-project │ │ ┌────────────────┬─────────────────┐ │ │ │ │ │ │ │ │ Neovim │ Claude Code │ │ │ │ (寫程式) │ (AI 助手) │ │ │ │ │ │ │ │ ├────────────────┴─────────────────┤ │ │ │ Shell (跑測試、git 操作) │ │ │ └──────────────────────────────────┘ │ └──────────────────────────────────────┘ 所有工作在同一個 terminal 視窗中完成。不切換應用程式、不碰滑鼠、不離開鍵盤。 ...

2026年3月4日 · 5 min · 997 words · Jack

Neovim 系列(十一):打造你的快捷鍵系統——which-key 與 Leader Key 設計哲學

這是 Neovim 從零開始系列的第十一篇。整個系列共 12 篇文章,將帶你從完全不懂 Vim,到能用 Neovim 打造一個完整的現代化開發環境。 快捷鍵的困境 到目前為止,我們已經設定了大量的快捷鍵:LSP 操作、Telescope 搜尋、Git 操作、Terminal 切換… 如果你覺得開始記不住了,這很正常。 解決方案不是「全部背下來」,而是用一套有邏輯的系統來組織它們,加上一個可探索的提示工具。 這就是 which-key.nvim 的用處。 which-key.nvim:按鍵提示器 which-key 的功能很簡單:當你按下一個前綴鍵(如 <leader>)後稍微等一下,它會彈出一個面板,顯示所有可用的下一步按鍵和它們的功能。 按下 <Space>(leader key)後等待... ┌─────────────────────────────────┐ │ ╭──── Leader Key ─────────────╮ │ │ │ b → Buffers │ │ │ │ c → Code actions │ │ │ │ d → Delete to void │ │ │ │ e → Diagnostics │ │ │ │ f → Find (Telescope) │ │ │ │ g → Git │ │ │ │ h → Hunk (Git changes) │ │ │ │ l → LSP │ │ │ │ q → Quit │ │ │ │ s → Split │ │ │ │ t → Terminal │ │ │ │ w → Save │ │ │ ╰─────────────────────────────╯ │ └─────────────────────────────────┘ 你不需要記住所有快捷鍵——只要記住前綴的邏輯分組,其他的讓 which-key 提醒你。 ...

2026年3月5日 · 4 min · 684 words · Jack

Neovim 系列(十二):從 VSCode 完全畢業——完整配置、痛點解法與學習資源

這是 Neovim 從零開始系列的第十二篇,也是最後一篇。整個系列共 12 篇文章,帶你從完全不懂 Vim,到能用 Neovim 打造一個完整的現代化開發環境。 恭喜你走到這裡 如果你從第一篇看到這裡,並且實際動手設定了你的 Neovim,那你已經擁有了一個功能完整、高度客製化的開發環境。讓我們回顧一下你已經學會的東西: 篇章 學會的技能 01 理解 modal editing 和 Vim 哲學 02 Vim 的語言系統:operator + motion/text object 03 完整的移動指令體系 04 Registers、Macros、Dot Command 05 安裝 Neovim、編寫 init.lua 06 用 lazy.nvim 管理 plugins 07 LSP + 自動補全 08 Treesitter + Telescope + 檔案導航 09 Git 整合工作流 10 Terminal 整合 + Claude Code 工作流 11 which-key 快捷鍵系統設計 12 完整配置總覽(你正在看的這篇) VSCode → Neovim 完整功能對照表 這張表是你遷移過程中最重要的參考。當你想做某件事但不知道在 Neovim 中怎麼做時,來這裡查: ...

2026年3月6日 · 4 min · 724 words · Jack

Hugo 完整教學指南 - 從零開始建立部落格

🚀 為什麼選擇 Hugo? Hugo 是一個超快速的靜態網站生成器,它的核心理念是: 你只需要寫 Markdown Hugo 自動轉換成美觀的 HTML 網站 建置速度極快(毫秒級) 不需要資料庫,純靜態檔案 📚 Hugo 的工作原理 content/ (你的 Markdown) → Hugo 處理 → public/ (生成的 HTML) 主要目錄說明 目錄 用途 需要編輯嗎? content/ 放置所有 Markdown 文章 ✅ 是 static/ 放置圖片、CSS、JS 等靜態資源 ✅ 需要時 hugo.toml 網站配置檔 ✅ 是 themes/ 主題模板 ❌ 通常不用 public/ Hugo 生成的網站 ❌ 絕對不要 archetypes/ 文章模板 🔧 偶爾 🛠️ 安裝與設定 1. 安裝 Hugo # macOS brew install hugo # Windows (使用 Chocolatey) choco install hugo-extended # Linux snap install hugo 2. 創建新網站 hugo new site myblog cd myblog 3. 安裝主題(以 PaperMod 為例) git init git submodule add --depth=1 https://github.com/adityatelange/hugo-PaperMod.git themes/PaperMod 4. 基本配置 (hugo.toml) baseURL = 'https://yourdomain.com/' languageCode = 'zh-tw' title = '我的部落格' theme = 'PaperMod' [pagination] pagerSize = 5 [params] defaultTheme = 'auto' ShowReadingTime = true ShowShareButtons = true ShowPostNavLinks = true ShowBreadCrumbs = true ShowCodeCopyButtons = true ShowWordCount = true ShowToc = true TocOpen = false ✍️ 如何新增文章 方法 1:使用 Hugo 命令(推薦) hugo new posts/my-new-post.md 方法 2:手動創建 Markdown 在 content/posts/ 目錄下創建 .md 檔案 ...

2025年8月14日 · 3 min · 572 words · Jack