" Test for the comment package
CheckRunVimInTerminal
func Test_basic_comment()
let lines =<< trim END
vim9script
def Hello()
echo "Hello"
enddef
END
let input_file = "test_basic_comment_input.vim"
call writefile(lines, input_file, "D")
let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
call term_sendkeys(buf, "gcc")
call term_sendkeys(buf, "2jgcip")
let output_file = "comment_basic_test.vim"
call term_sendkeys(buf, $":w {output_file}\<CR>")
defer delete(output_file)
call StopVimInTerminal(buf)
let result = readfile(output_file)
call assert_equal(["# vim9script", "", "# def Hello()", '# echo "Hello"', "# enddef"], result)
endfunc
:set ft=vimcommentstring is set to vim9script's #
commentstring should be set for legacy vim.
9.2.735
debian13, bash
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()
Oh, that is not so nice. I see @dkearns already self-assigned (thanks for that 🙏 ), I think we may need to make the guessing a bit smarter.
The following should skip over heredocs and:
diff --git a/runtime/ftplugin/vim.vim b/runtime/ftplugin/vim.vim index 21ca040fa..533f592e1 100644 --- a/runtime/ftplugin/vim.vim +++ b/runtime/ftplugin/vim.vim @@ -19,6 +19,26 @@ let b:did_ftplugin = 1 let s:cpo_save = &cpo set cpo&vim +func s:IsVim9Script() + let is_vim9 = v:false + let marker = '' + for line in getline(1, 32) + if !empty(marker) + " Inside a heredoc: look for the end marker + if line =~# $'^\s*{marker}$' + let marker = '' + endif + continue + endif + if line =~# '^\s*vim9\%[script]\>' + let is_vim9 = v:true + break + endif + let marker = matchstr(line, '=<<\s*\%(trim\s*\)\?\%(eval\s*\)\?\zs\w\+$') + endfor + return is_vim9 +endfunc + if !exists('*VimFtpluginUndo') func VimFtpluginUndo() setl fo< isk< com< tw< commentstring< include< define< keywordprg< omnifunc< path< @@ -107,7 +127,7 @@ command! -buffer -nargs=1 VimKeywordPrg :exe 'help' s:Help(<q-args>) 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 s:IsVim9Script() setlocal commentstring=#\ %s " Set 'comments' to format dashed lists in comments, for Vim9 script. setlocal com=sO:#\ -,mO:#\ \ ,eO:##,:#\\\ ,:#
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()