7 votes
Accepted

Why is Vim9 mentioned at all in the doc of Vim 8?

Because Vim9 has not been formally released yet, but the features are ready to try out in the latest Vim8 releases. If you see it in the help, then you can use it two ways: The Vim9 script syntax and ...
Chris Heithoff's user avatar
6 votes
Accepted

How can I convert vim8 function mapping to vim9?

I would go with :h vim9-differences before converting legacy to vim9 script. In your def function: remove last : string in def as function returns nothing let should be replaced with var a:command ...
Maxim Kim's user avatar
  • 13.4k
6 votes
Accepted

How to learn vimscript along with vim9script?

The main point of vim9script is to allow Vim plug-ins to access better performance for operations that are typically too slow to perform in the traditional vimscript and historically have required ...
5 votes
Accepted

How to unlet a variable in Vim 9 script?

Global variables are still the same as in legacy script, so unlet works as before. The only difference is that the prefix g: now is always required to access global variables. Unletting non-existent ...
Matt's user avatar
  • 20.7k
4 votes
Accepted

How do I :let a global variable in my vimrc in vim9script?

In general you have to declare the variable once using var vim9script var fortran_free_source = 1 is the equivalent of: let s:fortran_free_source=1 After the variable has been declared you can ...
Vivian De Smedt's user avatar
3 votes

Why is Vim9 mentioned at all in the doc of Vim 8?

To maintain backward compatibility, the commands you enter at the command-line prompt (:) are interpreted as pre-Vim9 legacy commands. You can prefix the command with 'vim9cmd' to interpret it as a ...
Yegappan Lakshmanan's user avatar
2 votes

How can I define vim9 functions and vim9 lambdas in a vim9 script?

In vim9script def should be without !. Not sure if def! should be allowed in legacy vimscript. All functions in vim9script are script local by default unless you export them or explicitly use g: as in ...
Maxim Kim's user avatar
  • 13.4k
2 votes
Accepted

How to export function conditionally in Vim9script?

I got a different error message: E1044: export with invalid argument: export def SomeHelperFunction__(bar: string): string Which led me to assume this was some form of bug, where either it isn't ...
Zoe is on strike's user avatar
2 votes

Vim9script commands from command line result in E1124. Is it normal?

This is because the commandline runs :legacy-mode by default unless :vim9cmd is used.
dza's user avatar
  • 231
2 votes
Accepted

Is there any way to automatically adjust OS specific environment variables, path, etc. format?

For environment variable you can use within Vim the Unix syntax: :echo $foo let $foo = 'bar' For the path I believe you can also use the Unix syntax (/ separated path) for all the Vim API.
Vivian De Smedt's user avatar
2 votes

Prevent <c-w>q to quit Vim when there is only one window left

For the sake of completeness and as requested by a user, here is the solution that I am currently using (based on a user comment): vim9script def QuitWindow() # Close window and wipe buffer but ...
Barzi2001's user avatar
  • 550
1 vote
Accepted

Vim9script autoloading script results in undefined variable

I was checking if g:loaded_termtoggle is true instead of false, dumb mistake. I also found that the plugin is getting sourced twice for some reason, so using get(g:, 'loaded_termtoggle', false) doesn'...
expoodo's user avatar
  • 11
1 vote

How to use prettier for formatting markdown files on save?

Here is a more canonical and holistic approach. Your question is specifically about formatting a buffer on write but formatting is a common thing that can be done in other scenarios and it turns out ...
romainl's user avatar
  • 40.6k
1 vote

How can I camel-case extant lowercase text?

There are a few plugins out there that do the job. And, shameless plug, I got mine: lh-style. In particular, you'll be interested in the command :NameConvert upper_camel_case (or lower...). As such ...
Luc Hermitte's user avatar
  • 17.4k
1 vote

Prevent <c-w>q to quit Vim when there is only one window left

I would do: vim9script def g:QuitWindow() # Close window and wipe buffer but prevent Vim to quit if one window is # left. if winnr('$') != 1 quit endif enddef nnoremap <c-w>...
Vivian De Smedt's user avatar
1 vote
Accepted

How to automatically close all the terminal buffers when closing vim with :qa?

use QuitPre or ExitPre instead of VimLeave Doc says Can be used to close any non-essential window vim9script def WipeoutTerminals() for buf_nr in term_list() exe "bw! " .. ...
balki's user avatar
  • 355
1 vote

How to automatically close all the terminal buffers when closing vim with :qa?

Here is something I did to leave automatically the "side bar". Defined here as: The terminal The quickfix window The NERDTree side bar function! IsSideBar(buf_nr) " Return 1 if the ...
Vivian De Smedt's user avatar
1 vote
Accepted

Vim9 vs legacy: are there any benefits in using interpolated strings over .. and in using "new" autoload over the "old" autoload mechanism?

As a scant answer, :help vim9script: Vim script has been growing over time, while preserving backwards compatibility. That means bad choices from the past often can't be changed and compatibility ...
D. Ben Knoble's user avatar
  • 26.1k
1 vote
Accepted

Vim9script commands from command line result in E1124. Is it normal?

To use the vim9 script syntax your script must include as the first command vim9script. vim9script var a = 1 On the command line to run vim9 script command you have to prefix them with :vim9 :vim9 g:...
Vivian De Smedt's user avatar
1 vote

Get the last line of Vim terminal output

The term_wait(150) function before reading the last line of the terminal buffer output solved it :-)
Tomáš Bažant's user avatar
1 vote
Accepted

vim9script syntax highlighting range

It is more readable with :help interpolated-string. Available in vim from May 2022 (> 8.2.4883). vim9script def HiLang(short_name: string, long_name: string) b:current_syntax = '' unlet b:...
balki's user avatar
  • 355
1 vote

vim9script syntax highlighting range

Your two functions looks similar, and lines that differ are the 4th and the 5th. From there, I think you'll need two parameters: Hi_Py Hi_Java line 4 line 5 py java @this start="#begin=this&...
gildux's user avatar
  • 264
1 vote
Accepted

How can I make 'quickfixtextfunc' work with cfilter using a vim9's "def" function?

The function created by "def" is script-local by default. On the other hand, the function created by "function" is global by default. The 'quickfixtextfunc' option should be set ...
Yegappan Lakshmanan's user avatar
1 vote
Accepted

'Undefined variable' error: why?

In Vim9 script :var is used to define a local variable that is not visible outside. Specify global scope g: directly or remove vim9script command as it is not doing much here anyway. Also to note that ...
Matt's user avatar
  • 20.7k
1 vote

How can I write an out_cb handler in vim9script?

This is official answer of Bram Moolenaar, hope this can help someone. 😊 In Vim9 script the type of the arguments is checked. That helps you writing correct functions, and once written it is easier ...
N i k o la y T h e B l o o d y's user avatar
1 vote
Accepted

How do I work with vim9 and unicode?

filbranden nudged me in the right direction in a comment. charcol('.') works around pure access based on the current cursor position, meaning line[charcol('.') - 1] returns the correct character for ...
Zoe is on strike's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible