@@ -51,6 +51,7 @@ The Vim9 script syntax and semantics are used in:
5151- a function defined with the `:def ` command
5252- a script file where the first command is `vim9script `
5353- an autocommand defined in the context of the above
54+ - a command prefixed with the `vim9cmd ` command modifier
5455
5556When using `:function ` in a Vim9 script file the legacy syntax is used, with
5657the highest | scriptversion | . However, this can be confusing and is therefore
@@ -60,6 +61,12 @@ Vim9 script and legacy Vim script can be mixed. There is no requirement to
6061rewrite old scripts, they keep working as before. You may want to use a few
6162`:def ` functions for code that needs to be fast.
6263
64+ *:vim9* *:vim9cmd*
65+ :vim9[cmd] {cmd}
66+ Execute {cmd} using Vim9 script syntax and semantics.
67+ Useful when typing a command and in a legacy script or
68+ function.
69+
6370==============================================================================
6471
65722. Differences from legacy Vim script *vim9-differences*
@@ -1044,9 +1051,9 @@ that you don't do that.
10441051Namespace ~
10451052 *vim9-namespace*
10461053To recognize a file that can be imported the `vim9script ` statement must
1047- appear as the first statement in the file. It tells Vim to interpret the
1048- script in its own namespace, instead of the global namespace. If a file
1049- starts with: >
1054+ appear as the first statement in the file (see | vim9-mix | for an exception).
1055+ It tells Vim to interpret the script in its own namespace, instead of the
1056+ global namespace. If a file starts with: >
10501057 vim9script
10511058 var myvar = 'yes'
10521059 Then "myvar" will only exist in this file. While without `vim9script ` it would
@@ -1066,6 +1073,27 @@ Vim default value, like with: >
10661073 One of the effects is that | line-continuation | is always enabled.
10671074The original value of 'cpoptions' is restored at the end of the script.
10681075
1076+ *vim9-mix*
1077+ There is one way to use both legacy and Vim9 syntax in one script file: >
1078+ " comments may go here
1079+ if !has('vim9script')
1080+ " legacy script commands go here
1081+ finish
1082+ endif
1083+ vim9script
1084+ # Vim9 script commands go here
1085+ This allows for writing a script that takes advantage of the Vim9 script
1086+ syntax if possible, but will also work on an Vim version without it.
1087+
1088+ This can only work in two ways:
1089+ 1. The "if" statement evaluates to false, the commands up to `endif ` are
1090+ skipped and `vim9script ` is then the first command actually executed.
1091+ 2. The "if" statement evaluates to true, the commands up to `endif ` are
1092+ executed and `finish ` bails out before reaching `vim9script ` .
1093+
1094+ TODO: The "vim9script" feature does not exist yet, it will only be added once
1095+ the Vim9 script syntax has been fully implemented.
1096+
10691097
10701098Export ~
10711099 *:export* *:exp*
0 commit comments