Skip to content

Latest commit

 

History

History
23 lines (22 loc) · 7.96 KB

vimscriptcomparison.md

File metadata and controls

23 lines (22 loc) · 7.96 KB

Vim Script Version Comparison Table

What Vim 8 Vim 9
first line
vim9script
comment sign
"
#
line continuation
echo "hello "
\ .. "world"
echo "hello "
.. "world"
variable declaration
let s:MyVar=0
var MyVar = 0
variable assignment
let s:MyVar=0
MyVar = 0
const
const and final
function definition
function MyFunc(Param) abort
echo a:Param
endfunction
def MyFunc(Param: number)
echo Param
enddef
function arguments dictionary Present as a: Absent. Arguments are accessed by name.
calling function
call MyFunc(42)
MyFunc(42)
Default scope of
variables and functions
global script-local
s: is optional.
On reloading script Nothing is removed Existing script-local variables and functions are removed.
ranges
%s/patt/repl/g
:%s/patt/repl/g
Lambda syntax
let l1 = {arg -> expression}
var l2 = (arg) => expression
White space around operator Does not matter Mostly needed
var name=234 # ✗
var name = 234 # ✓
Expression within
variable name
Allowed
var_{1+1} creates variable named var_2
Not allowed
Literal keys in dictionary
let dict = #{key: value}
var dict = {key: value}
After encountering first error Continues Stops
Increment and decrement operator Absent Present although not in an expression yet. E.g., ++myvar and --myvar
map() function Item type in initial and final expression can differ.
" Item type changes from number to string
echo map([1, 2, 3], "'Value is ' .. v:val")
The item type of expression passed into map() must not change.
# Type Mismatch Error
echo map([1, 2, 3], "'Value is ' .. v:val")

Instead use mapnew().