3dyuval / 3dyuval/nvim

code fences support in surround operations

Aperta
#57 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Fennel
Stelle
0
Fork
0
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.