comparison runtime/doc/vim9.txt @ 23974:d4f7e4138544 v8.2.2529

patch 8.2.2529: Vim9: Not possible to use legacy and Vim9 script in one file Commit: https://github.com/vim/vim/commit/d3f8a9ee65b249d073343e43e423bc3348dd09d0 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Feb 17 21:57:03 2021 +0100 patch 8.2.2529: Vim9: Not possible to use legacy and Vim9 script in one file Problem: Vim9: Not possible to use legacy and Vim9 script in one file. Solution: Vim9: allow for "if false" before :vim9script. (closes https://github.com/vim/vim/issues/7851)
author Bram Moolenaar <Bram@vim.org>
date Wed, 17 Feb 2021 22:00:03 +0100
parents 2a885d095bff
children 54b2aa1f0d42
comparison
equal deleted inserted replaced
23973:5b97421c6d54 23974:d4f7e4138544
1049 1049
1050 1050
1051 Namespace ~ 1051 Namespace ~
1052 *vim9-namespace* 1052 *vim9-namespace*
1053 To recognize a file that can be imported the `vim9script` statement must 1053 To recognize a file that can be imported the `vim9script` statement must
1054 appear as the first statement in the file. It tells Vim to interpret the 1054 appear as the first statement in the file (see |vim9-mix| for an exception).
1055 script in its own namespace, instead of the global namespace. If a file 1055 It tells Vim to interpret the script in its own namespace, instead of the
1056 starts with: > 1056 global namespace. If a file starts with: >
1057 vim9script 1057 vim9script
1058 var myvar = 'yes' 1058 var myvar = 'yes'
1059 Then "myvar" will only exist in this file. While without `vim9script` it would 1059 Then "myvar" will only exist in this file. While without `vim9script` it would
1060 be available as `g:myvar` from any other script and function. 1060 be available as `g:myvar` from any other script and function.
1061 1061
1070 A side effect of `:vim9script` is that the 'cpoptions' option is set to the 1070 A side effect of `:vim9script` is that the 'cpoptions' option is set to the
1071 Vim default value, like with: > 1071 Vim default value, like with: >
1072 :set cpo&vim 1072 :set cpo&vim
1073 One of the effects is that |line-continuation| is always enabled. 1073 One of the effects is that |line-continuation| is always enabled.
1074 The original value of 'cpoptions' is restored at the end of the script. 1074 The original value of 'cpoptions' is restored at the end of the script.
1075
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.
1075 1096
1076 1097
1077 Export ~ 1098 Export ~
1078 *:export* *:exp* 1099 *:export* *:exp*
1079 Exporting an item can be written as: > 1100 Exporting an item can be written as: >