Questions tagged [vim9script]
A new, compiled, and experimental version of the scripting language embedded into Vim.
23
questions
1
vote
1
answer
39
views
Vim9 lambda function destructuring a list in arguments?
I tried to destructure a list in a lambda function, like this:
var matched = reduce(
mapnew(lines, (_, x) => [strpart(x, 0, 1), strpart(x, 2, 1)]),
(acc, [a, b]) => acc && a == &...
-1
votes
2
answers
54
views
Prevent <c-w>q to quit Vim when there is only one window left
I wish to close windows and wipe out the associated buffers with <c-w>q but at the same time I want to prevent to quit Vim when there is only one window left.
My attempt is as follows:
...
1
vote
1
answer
42
views
Is there any way to automatically adjust OS specific environment variables, path, etc. format?
Often in my scripts I have some ugly snippets like the following:
vim9script
var bin = ""
if has("win32")
bin = "\\bin"
else
bin = "/bin"
endif
g:...
0
votes
2
answers
122
views
How to automatically close all the terminal buffers when closing vim with :qa?
I am wondering if there is a way to automatically force-wipe all the running terminals when quitting Vim with :qa.
My attempt (that does not work):
vim9script
def WipeoutTerminals()
for buf_nr in ...
0
votes
2
answers
73
views
How to re-open the same window with the same buffer therein?
Consider the following snippet:
vim9script
# Set stuff in the newly created window
var my_win_nr = winnr('$')
var my_win_id = win_getid(my_win_nr)
win_execute(my_win_id, 'wincmd L')
win_execute(...
1
vote
1
answer
116
views
Vim9 vs legacy: are there any benefits in using interpolated strings over .. and in using "new" autoload over the "old" autoload mechanism?
I am wondering if it is just a matter of taste or if there is any benefit in using some of the new features in Vim9.
I am interested in interpolated-strings and the autoload mechanism.
interpolated-...
0
votes
0
answers
60
views
Plugin function scope issue
I have recently discovered this guide that was very eye opener under many aspects.
So I decided to do things "by the book" by moving my plugins in ~/.vim/pack/bundle/start/myplugin/plugin/...
0
votes
2
answers
69
views
How can I define a buffer-local variable in a FileType autocommand using vim9script?
I am trying to define a buffer variable based on the FileType as it follows:
vim9script
def g:MyComment(comment_symbol: string)
# Do something
enddef
augroup commenting_blocks_of_code
...
5
votes
1
answer
94
views
How to export function conditionally in Vim9script?
I have a plugin which exports a couple of functions. These functions depend on a few script-local functions. I want to test these script-local functions.
The best way I can think of to do that, ...
0
votes
2
answers
69
views
Vim9script commands from command line result in E1124. Is it normal?
If I run e.g. :var a = 1 from the command line I end up in E1124: "var" cannot be used in legacy vimscript. Running on MacVim 9.0.1276.
Is it normal behavior?
0
votes
1
answer
67
views
Get the last line of Vim terminal output
I use Vim for editing DocBook files. I created several functions that manipulate the text in the buffer. For example to build a PDF from the source using an external command. I run these functions ...
0
votes
3
answers
87
views
vim9script syntax highlighting range
I want to translate the following functions to vim9script
and also combine them into one because they basically do the same
function! Hi_Py()
let b:current_syntax=''
unlet b:current_syntax
...
0
votes
1
answer
79
views
How can I make 'quickfixtextfunc' work with cfilter using a vim9's "def" function?
On Windows 10, using gvim, when editing a file like the following example:
foo
foobar
baz
As long as I use a function and not a def, I can do the following and Cfilter will work as expected:
:...
5
votes
1
answer
380
views
How can I convert vim8 function mapping to vim9?
I have a function in vim8 as:
function! BSkipQuickFix(command)
let start_buffer = bufnr('%')
execute a:command
while &buftype ==# 'quickfix' && bufnr('%') != start_buffer
execute ...
1
vote
1
answer
510
views
How do I :let a global variable in my vimrc in vim9script?
I am trying to change my vimrc to vim9script. For inbuilt fortran help, (:h fortran)
we have:
:let fortran_free_source=1
This is giving an error:
E1126: Cannot use :let in Vim9 script
If I remove ...
1
vote
1
answer
414
views
How to unlet a variable in Vim 9 script?
In Vim9 script :let cannot be used. An existing variable is assigned to
without any command. The same for global, window, tab, buffer and Vim
variables, because they are not really declared. Those ...
0
votes
1
answer
475
views
'Undefined variable' error: why?
vim9script
set laststatus=2
set statusline=
var separator = ' '
set statusline+=%{expand('%:p')}
set statusline+=%{separator}
set statusline+=%l:%v
Error: Undefined variable: separator
Why is ...
7
votes
1
answer
669
views
How to learn vimscript along with vim9script?
I've finally made the decision to learn vimscript. I don't hate reading manual and really like the built-in help files, so I am starting with usr_41.txt and plan to read eval.txt afterwards.
Now as I ...
5
votes
0
answers
212
views
Issue when moving Vim9script plugin's functions to autoload
I've read :help write-plugin to understand a bit more about how to write a plugin in Vim9script, but there aspects of that that puzzle me.
Here's a very simplified, working version of the example ...
1
vote
1
answer
102
views
How can I write an out_cb handler in vim9script?
In §9 of :h channel is mentioned the legacy vimscript out_cb handler.
let job = job_start(command, {"out_cb": "MyHandler"})
The function will be called with the channel and a ...
2
votes
1
answer
1k
views
How can I define vim9 functions and vim9 lambdas in a vim9 script?
In :help vim9 I read
The Vim9 script syntax and semantics are used in:
a function defined with the :def command
a script file where the first command is vim9script
an autocommand defined in the ...
7
votes
2
answers
2k
views
Why is Vim9 mentioned at all in the doc of Vim 8?
Looking for lambda in the doc, I've found out (to my surprise) that they do exist in vimscript, and they use the syntax {args -> expr1}.
But I've also discovered that there's Vim9, the doc of which ...
2
votes
1
answer
389
views
How do I work with vim9 and unicode?
I've found myself in a bit of an interesting situation.
I'm writing a plugin in which I need to do a tiny bit of line parsing.
Given a file:
æøå
It's easy to verify that col('.') returns 1, 3, and 5 ...