vim9script below a commentExample file:
##############################
# #
# Custom Functions #
# #
##############################
vim9script
command! Cnext try | cbelow | catch | cabove 9999 | catch | endtry
nnoremap <leader>m :Cnext<CR>
# Append modeline after last line in buffer.
# Use substitute() instead of printf() to handle '%%s' modeline in LaTeX
# files.
function! AppendModeline()
let l:modeline = printf(" vim: set ts=%d sw=%d tw=%d %set :",
\ &tabstop, &shiftwidth, &textwidth, &expandtab ? '' : 'no')
let l:modeline = substitute(&commentstring, "%s", l:modeline, "")
call append(line("$"), ['', l:modeline])
endfunction
nnoremap <Leader>sm :call AppendModeline()<CR>
function! AddSubtract(char, back)
let pattern = &nrformats =~ 'alpha' ? '[[:alpha:][:digit:]]' : '[[:digit:]]'
call search(pattern, 'cw' . a:back)
execute 'normal! ' . v:count1 . a:char
silent! call repeat#set(":\<C-u>call AddSubtract('" .a:char. "', '" .a:back. "')\<CR>")
endfunction
nnoremap <silent> <C-a> :<C-u>call AddSubtract("\<C-a>", '')<CR>
nnoremap <silent> <Leader><C-a> :<C-u>call AddSubtract("\<C-a>", 'b')<CR>
nnoremap <silent> <C-x> :<C-u>call AddSubtract("\<C-x>", '')<CR>
nnoremap <silent> <Leader><C-x> :<C-u>call AddSubtract("\<C-x>", 'b')<CR>
# vim: set ts=4 sw=4 tw=78 et :
This results in Vim chocking on the use of # instead of " as the comment.
If vim9script is on the first line, like a shebang line in a script, then it works as expected. Yet according to the vim9 help text the vim9script just needs to be the first command.
One of the following I guess:
vim9script should be treated like a sheban line" and # as a comment (probably harder due to legacy vim script support)9.0
Operating System: Arch Linux
Terminal: Konsole
Shell: Elvish
Error detected while processing /home/vendion/.vim/vimrc[34]../home/vendion/.vim/functions.vim: line 1: E749: Empty buffer line 2: E749: Empty buffer line 3: E488: Trailing characters: Custom Functions #: # Custom Functions # line 4: E749: Empty buffer line 5: E749: Empty buffer line 7: E1039: "vim9script" must be the first command in a script line 12: E488: Trailing characters: Append modeline after last line in buffer.: # Append modeline after last line in buffer. line 13: E488: Trailing characters: Use substitute() instead of printf() to handle '%%s' modeline in LaTeX: # Use substitute() instead of printf() to handle '%%s' modeline in LaTeX line 14: E488: Trailing characters: files.: # files. line 34: E488: Trailing characters: vim: set ts=4 sw=4 tw=78 et :: # vim: set ts=4 sw=4 tw=78 et : Press ENTER or type command to continue
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
The help is correct, "vim9script" must be the first command. But until it's found, comments are handled like in legacy script.
That is why it is stated that it's best to put "vim9script" in the very first line.
A comment is not a command, in case that is your confusion.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Closed #10644 as completed.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Maybe I overlooked it, but reading through this https://vimhelp.org/vim9.txt.html I don't see where it says it needs to be the first line only the first command which is what caused my confusion.
The only places where I see "first line" are in the following:
Note th[a](https://vimhelp.org/insert.txt.html#a)t this means that in heredoc the first line cannot start with a bar:
var lines =<< trim END
| this doesn't work
END
Since [a](https://vimhelp.org/insert.txt.html#a) continuation line cannot be easily recognized the parsing of commands
has been made stricter. E.g., because of the error in the first line, the
second line [is](https://vimhelp.org/motion.txt.html#is) seen [as](https://vimhelp.org/motion.txt.html#as) [a](https://vimhelp.org/insert.txt.html#a) separate command:
popup_create(some invalid expression, {
exit_cb: Func})
I only see the following:
- a script file where the first command is vim9script
Which doesn't imply that it should be first line and there cannot be any comments before it. It would be clearer if it read
"a script file where the first line is vim9script"
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()