From 93b3ea26ac9b7634104f86af02fb392daa25d491 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 10 Apr 2026 07:28:24 +0800 Subject: [PATCH] vim-patch:9.2.0327: filetype: uv scripts are not detected (#38920) Problem: filetype: uv scripts are not detected (Asger Hautop Drewsen) Solution: Detect uv scripts as python filetype if the shebang line contains "uv run" Reference: https://docs.astral.sh/uv/guides/scripts/#using-a-shebang-to-create-an-executable-file fixes: vim/vim#19941 https://github.com/vim/vim/commit/6c16ccaf6101a5a4fa28df9ca31e0bf871541aa4 Co-authored-by: Christian Brabandt --- runtime/lua/vim/filetype/detect.lua | 4 ++++ test/old/testdir/test_filetype.vim | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index 1b624b7022..1680c316bf 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -2162,6 +2162,10 @@ local function match_from_hashbang(contents, path, dispatch_extension) end end + if name == 'uv' and matchregex(first_line, [[\]]) then + return 'python' + end + -- If nothing matched, check the extension table. For a hashbang like -- '#!/bin/env foo', this will set the filetype to 'fooscript' assuming -- the filetype for the 'foo' extension is 'fooscript' in the extension table. diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim index 5d42d65e43..ae2afec370 100644 --- a/test/old/testdir/test_filetype.vim +++ b/test/old/testdir/test_filetype.vim @@ -1106,7 +1106,8 @@ func s:GetScriptChecks() abort \ 'php': [['#!/path/php']], \ 'python': [['#!/path/python'], \ ['#!/path/python2'], - \ ['#!/path/python3']], + \ ['#!/path/python3'], + \ ['#!/usr/bin/env -S uv run --script']], \ 'groovy': [['#!/path/groovy']], \ 'ruby': [['#!/path/ruby']], \ 'javascript': [['#!/path/node'],