-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
@Konfekt a few things that came to light when I jumped in to look at the new https://learnxinyminutes.com/vim9script/
Fixes
- When I added a bunch of the content months ago, it included this comment:
# You can run this Vim9 script directly in Vim. After pasting the content
# into a Vim buffer, enter the command `so` in command-line mode (press `:`
# first to enter command-line mode).
That was correct at that point; problem is, with some of the more recent additions, that no longer works. Fixes needed:
Lines 486-488: The normal! ggddGp, and related comments, should be replaced with something that does not change the buffer. I suggest this:
# You can run normal commands from Vim9 script:
# This executes like pressing `"aY` in normal mode and then echos the `a` register
normal! "aY
echo @a
- Lines 519-525 require one correction (a missing
:) but, to ensure the following two commands don't replace/change the buffer, two commands should be moved to adef. Further, I think changing it to something that will work, regardless of the OS, too would be better, e.g., this works in any Linux, pwsh, and even cmd.exe:
# output username info
# ... to non-interactive shell
:!whoami
# more examples (in a def here to avoid replacing this script's contents)
def MoreExamples(): void
# ... to current buffer, replacing its contents
:%!whoami
# ... to the same buffer, appending at cursor position
:.read! whoami
enddef
- The
GitDiffQFcommand and its function would ideally be more idiomatic. Especially,callshould not be there before the linesetqflist(qf_list, 'r'). And types, adding,: list<string>tovar diff_linesand using: list<any>(instead of= []) too, ideally:
def GitDiffQuickfix()
var diff_lines: list<string> = systemlist('git diff --name-only')
if v:shell_error != 0
echo 'Git not available or not a repo'
return
endif
var qf_list: list<any>
for file in diff_lines
add(qf_list, {'filename': file, 'lnum': 1, 'text': 'Modified file'})
endfor
setqflist(qf_list, 'r')
copen
enddef
command! GitDiffQF GitDiffQuickfix()
Making these changes avoids the errors that occur if you do try to copy the whole script and source it as it is now.
Consistency and naming
There are many uses of "Vim9Script". Vim's documentation uses "Vim9 script" - it would be better to replace all "Vim9Script" accordingly - refer https://vimhelp.org/vim9.txt.html - NB: That does not include where the vim9script namespace is used or referenced, though.
Similarly, there are many instances of, "legacy Vimscript" and "legacy vimscript", which should be changed to, "legacy Vim script", also to be consistent with Vim's documentation.
Contributors
Adding @ubaldot and me - @kennypete - would reflect the efforts on this?
PR?
I'm not sure whether you'll be coordinating any PRs, so if you'd prefer I do one, all good.