From 8daff33d2d4be31b6d73fedd5e5d16c8ca78b9a7 Mon Sep 17 00:00:00 2001 From: Jannik Donker Date: Wed, 5 Aug 2026 06:40:09 +0200 Subject: [PATCH] diff support in treesitter/fold --- lua/options.lua | 12 ++++++++++++ lua/plugins.lua | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lua/options.lua b/lua/options.lua index 1d1357d..ec2a7b0 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -24,6 +24,18 @@ vim.api.nvim_create_autocmd({ "FocusGained", "BufEnter", "CursorHold", "CursorHo command = "if mode() != 'c' | checktime | endif", }) +-- `git show`/`git diff`/`git log -p` piped into nvim (e.g. `git show | nvim -`) +-- arrive as stdin with no filename, so normal filetype detection never fires +-- and folding/highlighting silently stay off. Sniff the content instead. +vim.api.nvim_create_autocmd("StdinReadPost", { + callback = function() + local first = vim.fn.getline(1) + if first:match("^commit %x+") or first:match("^diff %-%-git ") or first:match("^From %x+") then + vim.bo.filetype = "diff" + end + end, +}) + vim.filetype.add({ extension = { asm = "asm", s = "asm", S = "asm" } }) vim.api.nvim_create_autocmd("FileType", { pattern = "asm", diff --git a/lua/plugins.lua b/lua/plugins.lua index 9464710..82f4ce6 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -275,7 +275,7 @@ require("nvim-treesitter").install({ "lua", "vim", "vimdoc", "bash", "c", "cpp", "rust", "python", "javascript", "typescript", "tsx", "svelte", "css", "html", "json", "toml", "yaml", "markdown", "markdown_inline", - "java", "typst", "vala", + "java", "typst", "vala", "diff", }) vim.api.nvim_create_autocmd("FileType", {