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 摘要。