3dyuval / 3dyuval/nvim

code fences support in surround operations

未关闭
#57 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Fennel
星标
0
派生
0
PR 合并指标
30 天内没有已合并 PR

描述

We want `cr`` (copy inner code block) to work from inside
fenced code blocks in markdown, even when cursor is inside
injected language (e.g., bash inside ```bash block).

Why Treesitter Textobjects Doesn't Work

- The @block.inner query exists in
queries/markdown/textobjects.scm
- BUT when cursor is inside the code block, treesitter uses the
bash parser (injected), not markdown
- Treesitter-textobjects only queries the current language tree,
missing the parent markdown tree

Solution

The function select_fenced_code_block(inner) already exists in
/home/yuv/.config/nvim/lua/utils/code.lua:131. It manually walks
the markdown tree to find the containing fenced_code_block node.

Just need to add operator-pending keymaps in
/home/yuv/.config/nvim/lua/config/keymaps.lua:

-- Code block text objects (works inside injected languages like
bash in markdown)
vim.keymap.set({ "o", "x" }, "r`", function()
code.select_fenced_code_block(true) end, { desc = "Inner code
block" })
vim.keymap.set({ "o", "x" }, "t`", function()
code.select_fenced_code_block(false) end, { desc = "Around code
block" })

Usage (Graphite layout)

- `cr`` - copy inner code block content
- `ct`` - copy outer code block (includes fences)
- `xr`` - delete inner code block
- `xt`` - delete outer code block
- nr` / nt` - visual select inner/outer

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。