-*vim9.txt* For Vim version 8.2. Last change: 2022 Feb 09
+*vim9.txt* For Vim version 8.2. Last change: 2022 Feb 11
VIM REFERENCE MANUAL by Bram Moolenaar
Functions and variables are script-local by default ~
*vim9-scopes*
When using `:function` or `:def` to specify a new function at the script level
-in a Vim9 script, the function is local to the script, as if "s:" was
-prefixed. Using the "s:" prefix is optional. To define a global function or
-variable the "g:" prefix must be used. For functions in a script that is to
-be imported and in an autoload script "export" needs to be used. >
+in a Vim9 script, the function is local to the script. Like prefixing "s:" in
+legacy script. To define a global function or variable the "g:" prefix must
+be used. For functions in a script that is to be imported and in an autoload
+script "export" needs to be used. >
def ThisFunction() # script-local
- def s:ThisFunction() # script-local
def g:ThatFunction() # global
export def Function() # for import and import autoload
< *E1058* *E1075*
When using `:function` or `:def` to specify a nested function inside a `:def`
function and no namespace was given, this nested function is local to the code
-block it is defined in. In a `:def` function it is not possible to define a
-script-local function. It is possible to define a global function by using
-the "g:" prefix.
+block it is defined in. It is not possible to define a script-local function.
+It is possible to define a global function by using the "g:" prefix.
When referring to a function and no "s:" or "g:" prefix is used, Vim will
search for the function:
script "s:funcref" could be used, because it could not be referred to with
"funcref". In Vim9 script it can, therefore "s:Funcref" must be used to avoid
that the name interferes with builtin functions.
+ *vim9-s-namespace*
+The use of the "s:" prefix is not supported at the Vim9 script level. All
+functions and variables without a prefix are script-local.
+In :def functions the use of "s:" is optional. This is because in legacy
+script the "s:" might be needed. Disallowing the use of "s:" only in a :def
+function in Vim9 script would be a bit confusing.
+In legacy functions the use of "s:" for script items is required, as before.
In all cases the function must be defined before used. That is when it is
called, when `:defcompile` causes it to be compiled, or when code that calls
" Attached is a Vim script file for turning gvim into a shell script editor.
" It may also be used as an example how to use menus in Vim.
"
-" Written by: Lennart Schultz <les@dmi.min.dk>
+" Maintainer: Ada (Haowen) Yu <me@yuhaowen.com>
+" Original author: Lennart Schultz <les@dmi.min.dk> (mail unreachable)
-imenu Stmts.for for in \rdo\r\rdone\eki \ekk0elli
-imenu Stmts.case case in\r) ;;\resac\ebki \ek0elli
-imenu Stmts.if if \rthen\r\rfi\eki \ekk0elli
-imenu Stmts.if-else if \rthen\r\relse\r\rfi\eki \ekki \ekk0elli
-imenu Stmts.elif elif \rthen\r\r\eki \ekk0elli
-imenu Stmts.while while \rdo\r\rdone\eki \ekk0elli
+" Make sure the '<' and 'C' flags are not included in 'cpoptions', otherwise
+" <CR> would not be recognized. See ":help 'cpoptions'".
+let s:cpo_save = &cpo
+set cpo&vim
+
+imenu Stmts.for for in <CR>do<CR><CR>done<esc>ki <esc>kk0elli
+imenu Stmts.case case in<CR>) ;;<CR>esac<esc>bki <esc>k0elli
+imenu Stmts.if if <CR>then<CR><CR>fi<esc>ki <esc>kk0elli
+imenu Stmts.if-else if <CR>then<CR><CR>else<CR><CR>fi<esc>ki <esc>kki <esc>kk0elli
+imenu Stmts.elif elif <CR>then<CR><CR><esc>ki <esc>kk0elli
+imenu Stmts.while while do<CR><CR>done<esc>ki <esc>kk0elli
imenu Stmts.break break
imenu Stmts.continue continue
-imenu Stmts.function () {\r\r}\eki \ek0i
+imenu Stmts.function () {<CR><CR>}<esc>ki <esc>k0i
imenu Stmts.return return
imenu Stmts.return-true return 0
imenu Stmts.return-false return 1
imenu Stmts.exit exit
imenu Stmts.shift shift
imenu Stmts.trap trap
-imenu Test.existence [ -e ]\ehi
-imenu Test.existence\16 -\16 file [ -f ]\ehi
-imenu Test.existence\16 -\16 file\16 (not\16 empty) [ -s ]\ehi
-imenu Test.existence\16 -\16 directory [ -d ]\ehi
-imenu Test.existence\16 -\16 executable [ -x ]\ehi
-imenu Test.existence\16 -\16 readable [ -r ]\ehi
-imenu Test.existence\16 -\16 writable [ -w ]\ehi
-imenu Test.String\16 is\16 empty [ x = "x$" ]\ehhi
-imenu Test.String\16 is\16 not\16 empty [ x != "x$" ]\ehhi
-imenu Test.Strings\16 is\16 equal [ "" = "" ]\ehhhhhhhi
-imenu Test.Strings\16 is\16 not\16 equal [ "" != "" ]\ehhhhhhhhi
-imenu Test.Values\16 is\16 greater\16 than [ -gt ]\ehhhhhhi
-imenu Test.Values\16 is\16 greater\16 equal [ -ge ]\ehhhhhhi
-imenu Test.Values\16 is\16 equal [ -eq ]\ehhhhhhi
-imenu Test.Values\16 is\16 not\16 equal [ -ne ]\ehhhhhhi
-imenu Test.Values\16 is\16 less\16 than [ -lt ]\ehhhhhhi
-imenu Test.Values\16 is\16 less\16 equal [ -le ]\ehhhhhhi
-imenu ParmSub.Substitute\16 word\16 if\16 parm\16 not\16 set ${:-}\ehhi
-imenu ParmSub.Set\16 parm\16 to\16 word\16 if\16 not\16 set ${:=}\ehhi
-imenu ParmSub.Substitute\16 word\16 if\16 parm\16 set\16 else\16 nothing ${:+}\ehhi
-imenu ParmSub.If\16 parm\16 not\16 set\16 print\16 word\16 and\16 exit ${:?}\ehhi
-imenu SpShVars.Number\16 of\16 positional\16 parameters ${#}
-imenu SpShVars.All\16 positional\16 parameters\16 (quoted\16 spaces) ${*}
-imenu SpShVars.All\16 positional\16 parameters\16 (unquoted\16 spaces) ${@}
-imenu SpShVars.Flags\16 set ${-}
-imenu SpShVars.Return\16 code\16 of\16 last\16 command ${?}
-imenu SpShVars.Process\16 number\16 of\16 this\16 shell ${$}
-imenu SpShVars.Process\16 number\16 of\16 last\16 background\16 command ${!}
+imenu Test.existence [ -e ]<esc>hi
+imenu Test.existence\ -\ file [ -f ]<esc>hi
+imenu Test.existence\ -\ file\ (not\ empty) [ -s ]<esc>hi
+imenu Test.existence\ -\ directory [ -d ]<esc>hi
+imenu Test.existence\ -\ executable [ -x ]<esc>hi
+imenu Test.existence\ -\ readable [ -r ]<esc>hi
+imenu Test.existence\ -\ writable [ -w ]<esc>hi
+imenu Test.String\ is\ empty [ x = "x$" ]<esc>hhi
+imenu Test.String\ is\ not\ empty [ x != "x$" ]<esc>hhi
+imenu Test.Strings\ is\ equal [ "" = "" ]<esc>hhhhhhhi
+imenu Test.Strings\ is\ not\ equal [ "" != "" ]<esc>hhhhhhhhi
+imenu Test.Values\ is\ greater\ than [ -gt ]<esc>hhhhhhi
+imenu Test.Values\ is\ greater\ equal [ -ge ]<esc>hhhhhhi
+imenu Test.Values\ is\ equal [ -eq ]<esc>hhhhhhi
+imenu Test.Values\ is\ not\ equal [ -ne ]<esc>hhhhhhi
+imenu Test.Values\ is\ less\ than [ -lt ]<esc>hhhhhhi
+imenu Test.Values\ is\ less\ equal [ -le ]<esc>hhhhhhi
+imenu ParmSub.Substitute\ word\ if\ parm\ not\ set ${:-}<esc>hhi
+imenu ParmSub.Set\ parm\ to\ word\ if\ not\ set ${:=}<esc>hhi
+imenu ParmSub.Substitute\ word\ if\ parm\ set\ else\ nothing ${:+}<esc>hhi
+imenu ParmSub.If\ parm\ not\ set\ print\ word\ and\ exit ${:?}<esc>hhi
+imenu SpShVars.Number\ of\ positional\ parameters ${#}
+imenu SpShVars.All\ positional\ parameters\ (quoted\ spaces) ${*}
+imenu SpShVars.All\ positional\ parameters\ (unquoted\ spaces) ${@}
+imenu SpShVars.Flags\ set ${-}
+imenu SpShVars.Return\ code\ of\ last\ command ${?}
+imenu SpShVars.Process\ number\ of\ this\ shell ${$}
+imenu SpShVars.Process\ number\ of\ last\ background\ command ${!}
imenu Environ.HOME ${HOME}
imenu Environ.PATH ${PATH}
imenu Environ.CDPATH ${CDPATH}
imenu Builtins.wait wait
imenu Set.set set
imenu Set.unset unset
-imenu Set.mark\16 modified\16 or\16 modified\16 variables set -a
-imenu Set.exit\16 when\16 command\16 returns\16 non-zero\16 exit\16 code set -e
-imenu Set.Disable\16 file\16 name\16 generation set -f
-imenu Set.remember\16 function\16 commands set -h
-imenu Set.All\16 keyword\16 arguments\16 are\16 placed\16 in\16 the\16 environment set -k
-imenu Set.Read\16 commands\16 but\16 do\16 not\16 execute\16 them set -n
-imenu Set.Exit\16 after\16 reading\16 and\16 executing\16 one\16 command set -t
-imenu Set.Treat\16 unset\16 variables\16 as\16 an\16 error\16 when\16 substituting set -u
-imenu Set.Print\16 shell\16 input\16 lines\16 as\16 they\16 are\16 read set -v
-imenu Set.Print\16 commands\16 and\16 their\16 arguments\16 as\16 they\16 are\16 executed set -x
+imenu Set.mark\ modified\ or\ modified\ variables set -a
+imenu Set.exit\ when\ command\ returns\ non-zero\ exit\ code set -e
+imenu Set.Disable\ file\ name\ generation set -f
+imenu Set.remember\ function\ commands set -h
+imenu Set.All\ keyword\ arguments\ are\ placed\ in\ the\ environment set -k
+imenu Set.Read\ commands\ but\ do\ not\ execute\ them set -n
+imenu Set.Exit\ after\ reading\ and\ executing\ one\ command set -t
+imenu Set.Treat\ unset\ variables\ as\ an\ error\ when\ substituting set -u
+imenu Set.Print\ shell\ input\ lines\ as\ they\ are\ read set -v
+imenu Set.Print\ commands\ and\ their\ arguments\ as\ they\ are\ executed set -x
+
+" Restore the previous value of 'cpoptions'.
+let &cpo = s:cpo_save
+unlet s:cpo_save