Skip to content

Commit f0b0456

Browse files
committed
add initial paragraphs comparing to legacy Vimscript
1 parent 57d988a commit f0b0456

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

vim9script.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,31 @@ contributors:
88
---
99

1010
Vim9Script is a modern scripting language introduced in Vim 9.0.
11-
It is designed to replace legacy Vimscript (also called VimL), which is a sequence of ex-commands enhanced with scripting constructs like variables, functions, and control flow.
1211

13-
Unlike legacy Vimscript, Vim9Script enforces stricter syntax, improves performance, and supports modern programming features such as strong typing, classes, lambdas, and modules.
12+
Vim9script, which is exclusive to Vim version 9+, improves on its predecessor, legacy Vimscript, also called VimL, which is a sequence of ex-commands enhanced with scripting constructs like variables, functions, and control flow.
13+
Legacy Vimscript is interpreted line by line, requiring backslashes to continue lines, and commands like `let` and `call` are used to make them resemble ex-commands.
14+
15+
In contrast, Vim9script supports multi-line syntax natively, without needing line continuation.
16+
This makes it less suited for command-line usage, unlike traditional ex-commands, so that Vim9Script complements these for scripting.
17+
18+
Vim9Script enforces stricter syntax, improves performance, and supports modern programming features such as strong typing, classes, lambdas, and modules.
19+
Differences (see https://vimhelp.org/vim9.txt.html#vim9-differences) include:
20+
21+
1. New syntax basics
22+
• Comments start with `#` instead of `"`.
23+
• Line-continuation backslashes are rarely needed --- just concatenate with `..`.
24+
• Whitespace is significant in many places to keep things readable.
25+
26+
2. Variables and constants
27+
• Declare regular variables with `:var`, e.g. `var count = 0`
28+
• Change them with standard operators (`count += 3`) --- no more `:let`.
29+
• Declare immutable names with `:const` or `:final`.
30+
31+
3. Typed, script-local functions
32+
• All functions (and variables) are script-local by default.
33+
• Use `:def` with typed params and a return type, e.g.
34+
`def foo(x: number, y: string): bool`
35+
• Call them like normal functions (no `:call`).
1436

1537
Try [vim9-conversion-aid](https://github.com/ubaldot/vim9-conversion-aid) as a starting point to convert legacy Vimscript to Vim9Script.
1638

@@ -25,6 +47,10 @@ vim9script
2547
# There is no distinction between single and multi-line comments.
2648
# Use # inside a line at any position to comment out all following characters.
2749
50+
# You can run this Vim9 script directly in Vim. After pasting the content
51+
# into a Vim buffer, enter the command `so` in command-line mode (press `:`
52+
# first to enter command-line mode).
53+
2854
##################################################################
2955
## 1. Primitive types, collection types, operators, and regex
3056
##################################################################
@@ -112,7 +138,7 @@ echo v:numbersize # echos either 32 or 64
112138
# permitted value, for 64-bit 9,223,372,036,854,775,807, will fail:
113139
echo 9223372036854775807 + 1 # -9223372036854775808
114140
115-
# Numbers may be expressed as decimal, hexadecimal (prefixed with 0x),
141+
# Numbers may be expressed as decimal, hexadecimal (prefixed with 0x),
116142
# octal (0o or 0O), or binary (0b). These are all decimal 15:
117143
echo 15 + 0b1111 + 0xF + 0o17 # 60
118144
@@ -205,7 +231,7 @@ echo $PATH # (references the environment variable, PATH)
205231
206232
# Vim has many settings, which are also variables. They may be local or
207233
# global scoped.
208-
echo &textwidth # (echos the bufferlocal value of the textwidth option)
234+
echo &textwidth # (echos the buffer-local value of the textwidth option)
209235
echo &wildmenu # (echos the boolean value of command-line wildcard expansion)
210236
211237
@@ -375,7 +401,7 @@ var q: Quad = Quad.Square
375401
# result using string interpolation and showing multiple lines without `\`,
376402
# which is required in vimscript but not in Vim9 script.
377403
var result = $"A {tolower(q.name)} has {q.QuadProps()[0]} sides of equal " ..
378-
"length and " ..
404+
"length and " ..
379405
(q.QuadProps()[1] ? 'has only right angles' : 'has no right angle')
380406
echo result
381407

0 commit comments

Comments
 (0)