Questions tagged [vim9script]
A new, compiled, and experimental version of the scripting language embedded into Vim.
30
questions
1
vote
0
answers
22
views
input() function: is it possible to distinguish when user hit <esc> or <enter> keys?
As per question. If in my script I have input('Add your text here:') and run it, is there a way to distinguish if at some point user hit enter or esc?
2
votes
2
answers
168
views
How to load a function from a Vim9 script and call it?
If I save this simple script in a file:
vim9script
def Hi()
echo "Hello"
enddef
And I try to load and run it:
:so %
:call Hi()
I get:
E117: Unknown function: Hi
Can anyone explain?
I ...
1
vote
2
answers
81
views
How to add a third argument to a popup_menu() callback function?
So far, I know that you can pass only two arguments to popup callback functions. I am wondering if there is any way to pass a third argument? Shall I rely on some sort of closure or use some "...
0
votes
1
answer
35
views
remap with variables in the rhs
I want to remap <c-b> to foo<c-b>, being foo a number.
However, it seems it won't work with function local variables.
For instance, the following works:
vim9script
var foo = 4
if !...
0
votes
3
answers
178
views
Recommended way of scripting: Ex commands or vimscript functions?
While scripting I could achieve the same result both through Ex commands and vimscript functions, for example:
var filename = "foo.txt"
exe "new" filename # Ex ...
0
votes
1
answer
57
views
Vim9script autoloading script results in undefined variable
I'm new to vim9script and taking reference from this section of the vim9 help file. However I keep on getting this error upon calling TermOpen: E121: Undefined variable: util
autoload/util.vim:
" ...
0
votes
2
answers
120
views
How to use prettier for formatting markdown files on save?
I am wondering what could be an efficient way to achieve what I asked in the title.
The best I came out with is the following defined in ~/.vim/ftplugin/markdown.vim:
augroup PRETTIER
autocmd! * &...
1
vote
1
answer
71
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
88
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
52
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:...
1
vote
2
answers
233
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
117
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
202
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
80
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
110
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
197
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
121
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
115
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
107
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
112
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
452
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 ...
2
votes
1
answer
784
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
607
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 ...
1
vote
1
answer
667
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
1k
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
248
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
136
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
2k
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
442
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 ...