3dyuval / 3dyuval/nvim

code fences support in surround operations

Đang mở
#57 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Fennel
Star
0
Fork
0
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.