From 808fcc5a75eb143d358054e1a91588d3b4564ddb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 29 Jun 2026 06:31:59 +0800 Subject: [PATCH] vim-patch:9a899af: runtime(vim): Fix heredoc triggering misidentifcation of Vim9 script The following let-heredoc can cause legacy scripts to be misidentified as Vim9 script if it appears early in the file. Only match :vim9script at the start of a line where it sensibly belongs. let x =<< trim LINES vim9script ... LINES fixes: vim/vim#20647 (reported by Maxim Kim). closes: vim/vim#20654 https://github.com/vim/vim/commit/9a899af7e8e74bb094cfdfda857580b2e8ddf840 Co-authored-by: Doug Kearns --- runtime/ftplugin/vim.vim | 5 +++-- runtime/syntax/vim.vim | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/runtime/ftplugin/vim.vim b/runtime/ftplugin/vim.vim index 8cfaaafb66..8e86a185ff 100644 --- a/runtime/ftplugin/vim.vim +++ b/runtime/ftplugin/vim.vim @@ -5,7 +5,8 @@ " Contributors: Riley Bruins ('commentstring') " @Konfekt " @tpope (s:Help()) -" Last Change: 2026 May 31 +" @lacygoill +" Last Change: 2026 Jun 27 " Only do this when not done yet for this buffer if exists("b:did_ftplugin") @@ -103,7 +104,7 @@ command! -buffer -nargs=1 VimKeywordPrg :exe 'help' s:Help() setlocal keywordprg=:VimKeywordPrg " Comments starts with # in Vim9 script. We have to guess which one to use. -if "\n" .. getline(1, 32)->join("\n") =~# '\n\s*vim9\%[script]\>' +if "\n" .. getline(1, 32)->join("\n") =~# '\nvim9s\%[cript]\>' setlocal commentstring=#\ %s " Set 'comments' to format dashed lists in comments, for Vim9 script. setlocal com=sO:#\ -,mO:#\ \ ,eO:##,:#\\\ ,:# diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim index e4cf94b744..b20ba7280d 100644 --- a/runtime/syntax/vim.vim +++ b/runtime/syntax/vim.vim @@ -17,7 +17,8 @@ set cpo&vim " Feature testing {{{1 -let s:vim9script = "\n" .. getline(1, 32)->join("\n") =~# '\n\s*vim9\%[script]\>' +" NOTE: vimsyn_force_vim9 for internal use only +let s:vim9script = get(b:, "vimsyn_force_vim9", v:false) || "\n" .. getline(1, 32)->join("\n") =~# '\nvim9s\%[cript]\>' function s:has(feature) return has(a:feature) || index(get(g:, "vimsyn_vim_features", []), a:feature) != -1