一键导入
writing-lua
This snippet should be used when writing Neovim plugins with Lua, focusing on type safety, modular architecture, and best practices.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
This snippet should be used when writing Neovim plugins with Lua, focusing on type safety, modular architecture, and best practices.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when transcribing audio files with speaker diarization. Triggers on TRANSCRIBE keyword.
Create, update, delete, and query Google Calendar events using gcallm CLI, MCP tools, or direct API calls.
Rule-based methodology for essay development. Load this index first, then load specific essay type file based on task.
Comprehensive guide for managing Claude Code snippets v2.0 - discovering locations, creating snippets from files, searching by name/pattern/description, and validating configurations. Use this skill when users want to create, search, or manage snippet configurations in their Claude Code environment. Updated for LLM-friendly interface with TTY auto-detection.
Style guide and primer for writing in Warren Zhu's voice. Use when drafting emails, essays, blog posts, technical documents, consulting deliverables, presentations, or any writing for or as Warren. Covers philosophical sensibilities, stylistic patterns, characteristic moves, tone calibration, and professional/technical writing registers. Also useful when understanding Warren's intellectual background and preferences for advising him.
Use when interacting with Harvard Canvas LMS - fetching courses, assignments, grades, submissions, modules, calendar events. Trigger with CANVAS keyword.
| name | Writing Lua |
| description | This snippet should be used when writing Neovim plugins with Lua, focusing on type safety, modular architecture, and best practices. |
<Plug> mappings, not forced keymapsExtract when:
Target structure:
lua/plugin-name/
├── init.lua -- ~300 lines: setup, coordination, public API
├── operations.lua -- Core business logic
├── display.lua -- UI/rendering
├── config.lua -- Configuration
└── utils.lua -- Shared utilities
What Belongs in init.lua: ✅ Module requires, setup(), autocommands, keymap/command registration, public API (thin wrappers)
What Does NOT Belong: ❌ Complex logic (>10 lines/function), helper functions, data transformations, duplicate patterns
-- Before: Mixed concerns in init.lua (170 lines)
local function normalize_range() end
local function compute_visual_range() end
function M.add_annotation_from_visual()
local range = compute_visual_range(...)
end
-- After: Extracted to visual.lua
-- lua/plugin-name/visual.lua
local M = {}
function M.normalize_range(bufnr, range) end
function M.compute_visual_range(bufnr, opts) end
return M
-- init.lua becomes thin
local visual = require('plugin-name.visual')
function M.add_annotation_from_visual()
local range = visual.compute_visual_range(...)
require('plugin-name.operations').add_annotation(range)
end
-- Bad: 4 nearly identical functions
function M.show_tldr() ... popup.show_tldr(anno) end
function M.show_vsplit() ... popup.open_vsplit(anno) end
function M.show_hsplit() ... popup.open_hsplit(anno) end
function M.show_large() ... popup.open_large(anno) end
-- Good: Single dispatcher
---@param view_mode "tldr"|"vsplit"|"hsplit"|"large"
function M.show_annotation(view_mode)
local anno = get_annotation_at_cursor()
local handlers = {
tldr = function() popup.show_tldr(anno) end,
vsplit = function() popup.open_vsplit(anno) end,
hsplit = function() popup.open_hsplit(anno) end,
large = function() popup.open_large(anno) end,
}
handlers[view_mode]()
end
---@class Range
---@field start {line: integer, column: integer}
---@field ["end"] {line: integer, column: integer}
---@param opts PluginConfig?
---@return PluginConfig
local function setup(opts)
return vim.tbl_deep_extend("force", default_config, opts or {})
end
local M = {}
local default_config = { enabled = true, timeout = 5000 }
M.config = vim.deepcopy(default_config)
function M.setup(opts)
M.config = vim.tbl_deep_extend("force", M.config, opts or {})
end
local heavy
local function get_heavy()
if not heavy then heavy = require("heavy.module") end
return heavy
end
function M.action()
get_heavy().do_something()
end
vim.keymap.set("n", "<Plug>(plugin-action)", function()
require("plugin").action()
end, { desc = "Plugin action" })
local function dispatcher(opts)
local cmds = { enable = enable, disable = disable, status = status }
(cmds[opts.fargs[1]] or function()
vim.notify("Unknown: " .. opts.fargs[1], vim.log.levels.ERROR)
end)()
end
vim.api.nvim_create_user_command("Plugin", dispatcher, {
nargs = "+",
complete = function() return { "enable", "disable", "status" } end,
})
-- 0-indexed internally (LSP-style)
local range = {
start = { line = 0, column = 5 },
["end"] = { line = 0, column = 10 }
}
-- Convert to 1-indexed for storage
local function to_storage(range)
return {
start_line = range.start.line + 1,
start_col = range.start.column,
end_line = range["end"].line + 1,
end_col = range["end"].column
}
end
describe("plugin", function()
it("handles normal case", function()
assert.are.equal("expected", plugin.function("input"))
end)
end)
-- Dependency injection
M._http_get = function(url) return vim.fn.system("curl " .. url) end
function M.fetch() return M._http_get("https://api.example.com") end
local function read_file(path)
local ok, result = pcall(vim.fn.readfile, path)
if not ok then return nil, "Failed to read: " .. path end
return result, nil
end
local lines, err = read_file("config.json")
if err then
vim.notify(err, vim.log.levels.ERROR)
return
end
local ns_id = vim.api.nvim_create_namespace("plugin-name")
function add_highlight(bufnr, line, col_start, col_end)
return vim.api.nvim_buf_set_extmark(bufnr, ns_id, line, col_start, {
end_col = col_end,
hl_group = "PluginHighlight",
right_gravity = true,
end_right_gravity = false
})
end
vim.api.nvim_set_hl(0, "PluginHighlight", { fg = "#FFD700", underline = true })
local augroup = vim.api.nvim_create_augroup("PluginName", { clear = true })
vim.api.nvim_create_autocmd({ "BufReadPost", "BufNewFile" }, {
group = augroup,
callback = function(args) end,
desc = "Initialize plugin"
})
-- Cache expensive operations
local cache = {}
function M.get(key)
if not cache[key] then cache[key] = expensive_op(key) end
return cache[key]
end
-- Async with vim.schedule
vim.schedule(function() slow_computation() end)
-- Debounce
local timer
vim.api.nvim_create_autocmd("TextChanged", {
callback = function()
if timer then vim.fn.timer_stop(timer) end
timer = vim.fn.timer_start(500, on_change)
end
})
vim.api.nvim_buf_is_valid(buf)<Plug> mappings