1

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 the let, I am getting:

E492: Not an editor command:    fortran_free_source = 1

How should I update this?

1
  • Your question has no accepted answer. Is there an aspect of the question that has not been addressed? Otherwise maybe could you accept the response using the v green button. It allow the question to rest :-) Mar 25, 2023 at 6:40

1 Answer 1

4

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 modify it without using let.

vim9script

var fortran_free_source = 1

# I change my mind:
fortran_free_source = 0

But if you want to change a global variable they need not to be declared hence:

vim9script

# Set a global variable:
g:fortran_free_source = 1

is the equivalent of:

" Set a global variable:
let g:fortran_free_source=1
5
  • 4
    I think in this case it should just be: g:fortran_free_source = 1. Globals are not declared with "var" and the spaces around the equal sign are required.
    – Heptite
    Aug 27, 2022 at 4:27
  • Thanks @Heptite :-) I have adapted the solution accordingly. Aug 27, 2022 at 4:39
  • 1
    I would reword: "is equivalent of:" -- it is not. It would be the same as let s:fortran_free_source
    – Maxim Kim
    Aug 27, 2022 at 6:04
  • Thanks @Maxim, I was hesitating since if you are in a function I suppose x = 1 is equivalent to let a:x, let v:x = 1 or let s:x depending if x is a function argument n local variable or a script variable. Aug 27, 2022 at 6:22
  • 1
    let somevar = 1 in a function would be let l:somevar, in a script let s:somevar (provided there were no global var with the same name defined beforehand)
    – Maxim Kim
    Aug 27, 2022 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.