You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vim9script.md
+35-5Lines changed: 35 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,35 @@ contributors:
8
8
---
9
9
10
10
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.
12
11
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
+
(Ex commands, such as `:echo`, `:write`, `:substitute`, `:quit`, ... are commands that are part of the legacy Ex editor to execute a single action, one-liners without return values.)
14
+
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.
15
+
16
+
In contrast, Vim9script supports multi-line syntax natively, without needing line continuation.
17
+
This makes it less suited for command-line usage, unlike traditional ex-commands, so that Vim9Script complements these for scripting.
18
+
19
+
Vim9Script enforces stricter syntax, improves performance, and supports modern programming features such as strong typing, classes, lambdas, and modules.
20
+
Differences (see https://vimhelp.org/vim9.txt.html#vim9-differences) include:
21
+
22
+
1. New syntax basics
23
+
• Comments start with `#` instead of `"`.
24
+
• Line-continuation backslashes are rarely needed --- just concatenate with `..`.
25
+
• Whitespace is significant in many places to keep things readable.
26
+
27
+
2. Variables and constants
28
+
• Declare regular variables with `:var`, e.g. `var count = 0`
29
+
• Change them with standard operators (`count += 3`) --- no more `:let`.
30
+
• Declare immutable names with `:const` or `:final`.
31
+
32
+
3. Typed, script-local functions
33
+
• All functions (and variables) are script-local by default.
34
+
• Use `:def` with typed params and a return type, e.g.
35
+
`def foo(x: number, y: string): bool`
36
+
• Call them like normal functions (no `:call`).
37
+
38
+
All Ex commands can still be used inside functions and, vice-versa, you can call a function by an Ex command with `:vim9` (respectively `:call` in legacy vimscript) on the command line.
39
+
You can also define your own commands that call functions.
14
40
15
41
Try [vim9-conversion-aid](https://github.com/ubaldot/vim9-conversion-aid) as a starting point to convert legacy Vimscript to Vim9Script.
16
42
@@ -25,6 +51,10 @@ vim9script
25
51
# There is no distinction between single and multi-line comments.
26
52
# Use # inside a line at any position to comment out all following characters.
27
53
54
+
# You can run this Vim9 script directly in Vim. After pasting the content
55
+
# into a Vim buffer, enter the command `so` in command-line mode (press `:`
0 commit comments