code fences support in surround operations
- Lenguaje dominante
- Fennel
- Estrellas
- 0
- Forks
- 0
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Evaluación
Este issue todavía no se ha evaluado.