Mercurial > vim
comparison runtime/doc/vim9.txt @ 23392:517fca70e084 v8.2.2239
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Commit: https://github.com/vim/vim/commit/dcc58e031ded8b846a39146112b9b075cbb977d9
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Dec 28 20:53:21 2020 +0100
patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient
Problem: Vim9: concatenating lines with backslash is inconvenient.
Solution: Support concatenating lines starting with '|', useful for
:autocmd, :command, etc. (closes #6702)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 28 Dec 2020 21:00:04 +0100 |
parents | eb7d8f39363c |
children | 15fa3923cc49 |
comparison
equal
deleted
inserted
replaced
23391:3366c49544bc | 23392:517fca70e084 |
---|---|
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
7 THIS IS STILL UNDER DEVELOPMENT - ANYTHING CAN BREAK - ANYTHING CAN CHANGE | 7 THIS IS STILL UNDER DEVELOPMENT - ANYTHING CAN BREAK - ANYTHING CAN CHANGE |
8 | 8 |
9 Vim9 script commands and expressions. *Vim9* | 9 Vim9 script commands and expressions. *Vim9* *vim9* |
10 | 10 |
11 Most expression help is in |eval.txt|. This file is about the new syntax and | 11 Most expression help is in |eval.txt|. This file is about the new syntax and |
12 features in Vim9 script. | 12 features in Vim9 script. |
13 | 13 |
14 THIS IS STILL UNDER DEVELOPMENT - ANYTHING CAN BREAK - ANYTHING CAN CHANGE | 14 THIS IS STILL UNDER DEVELOPMENT - ANYTHING CAN BREAK - ANYTHING CAN CHANGE |
111 `:number` for that. > | 111 `:number` for that. > |
112 101 number | 112 101 number |
113 | 113 |
114 To improve readability there must be a space between a command and the # | 114 To improve readability there must be a space between a command and the # |
115 that starts a comment: > | 115 that starts a comment: > |
116 var = value # comment | 116 var name = value # comment |
117 var = value# error! | 117 var name = value# error! |
118 | 118 |
119 In legacy script # is also used for the alternate file name. In Vim9 script | 119 In legacy Vim script # is also used for the alternate file name. In Vim9 |
120 you need to use %% instead. Instead of ## use %%% (stands for all arguments). | 120 script you need to use %% instead. Instead of ## use %%% (stands for all |
121 arguments). | |
121 | 122 |
122 | 123 |
123 Vim9 functions ~ | 124 Vim9 functions ~ |
124 | 125 |
125 A function defined with `:def` is compiled. Execution is many times faster, | 126 A function defined with `:def` is compiled. Execution is many times faster, |
207 and variables are deleted, thus you start with a clean slate. This is useful | 208 and variables are deleted, thus you start with a clean slate. This is useful |
208 if you are developing a plugin and want to try a new version. If you renamed | 209 if you are developing a plugin and want to try a new version. If you renamed |
209 something you don't have to worry about the old name still hanging around. | 210 something you don't have to worry about the old name still hanging around. |
210 | 211 |
211 If you do want to keep items, use: > | 212 If you do want to keep items, use: > |
212 vimscript noclear | 213 vim9script noclear |
213 | 214 |
214 You want to use this in scripts that use a `finish` command to bail out at | 215 You want to use this in scripts that use a `finish` command to bail out at |
215 some point when loaded again. E.g. when a buffer local option is set: > | 216 some point when loaded again. E.g. when a buffer local option is set: > |
216 vimscript noclear | 217 vim9script noclear |
217 setlocal completefunc=SomeFunc | 218 setlocal completefunc=SomeFunc |
218 if exists('*SomeFunc') | finish | endif | 219 if exists('*g:SomeFunc') | finish | endif |
219 def g:SomeFunc() | 220 def g:SomeFunc() |
220 .... | 221 .... |
221 | 222 |
222 | 223 |
223 Variable declarations with :var, :final and :const ~ | 224 Variable declarations with :var, :final and :const ~ |
383 filter(list, (k, v) => | 384 filter(list, (k, v) => |
384 v > 0) | 385 v > 0) |
385 This does not work: > | 386 This does not work: > |
386 filter(list, (k, v) | 387 filter(list, (k, v) |
387 => v > 0) | 388 => v > 0) |
388 This also does not work: | 389 This also does not work: > |
389 filter(list, (k, | 390 filter(list, (k, |
390 v) => v > 0) | 391 v) => v > 0) |
392 But you can use a backslash to concatenate the lines before parsing: > | |
393 filter(list, (k, | |
394 \ v) | |
395 \ => v > 0) | |
391 | 396 |
392 Additionally, a lambda can contain statements in {}: > | 397 Additionally, a lambda can contain statements in {}: > |
393 var Lambda = (arg) => { | 398 var Lambda = (arg) => { |
394 g:was_called = 'yes' | 399 g:was_called = 'yes' |
395 return expression | 400 return expression |
402 | 407 |
403 | 408 |
404 Automatic line continuation ~ | 409 Automatic line continuation ~ |
405 | 410 |
406 In many cases it is obvious that an expression continues on the next line. In | 411 In many cases it is obvious that an expression continues on the next line. In |
407 those cases there is no need to prefix the line with a backslash | 412 those cases there is no need to prefix the line with a backslash (see |
408 |line-continuation|. For example, when a list spans multiple lines: > | 413 |line-continuation|). For example, when a list spans multiple lines: > |
409 var mylist = [ | 414 var mylist = [ |
410 'one', | 415 'one', |
411 'two', | 416 'two', |
412 ] | 417 ] |
413 And when a dict spans multiple lines: > | 418 And when a dict spans multiple lines: > |
439 ->BuilderSetWidth(333) | 444 ->BuilderSetWidth(333) |
440 ->BuilderSetHeight(777) | 445 ->BuilderSetHeight(777) |
441 ->BuilderBuild() | 446 ->BuilderBuild() |
442 var result = MyDict | 447 var result = MyDict |
443 .member | 448 .member |
449 | |
450 For commands that have an argument that is a list of commands, the | character | |
451 at the start of the line indicates line continuation: > | |
452 autocmd BufNewFile *.match if condition | |
453 | echo 'match' | |
454 | endif | |
444 | 455 |
445 < *E1050* | 456 < *E1050* |
446 To make it possible for the operator at the start of the line to be | 457 To make it possible for the operator at the start of the line to be |
447 recognized, it is required to put a colon before a range. This will add | 458 recognized, it is required to put a colon before a range. This will add |
448 "start" and print: > | 459 "start" and print: > |
939 You can cheat by using the global namespace explicitly. We will assume here | 950 You can cheat by using the global namespace explicitly. We will assume here |
940 that you don't do that. | 951 that you don't do that. |
941 | 952 |
942 | 953 |
943 Namespace ~ | 954 Namespace ~ |
944 *:vim9script* *:vim9* | 955 *vim9-namespace* |
945 To recognize a file that can be imported the `vim9script` statement must | 956 To recognize a file that can be imported the `vim9script` statement must |
946 appear as the first statement in the file. It tells Vim to interpret the | 957 appear as the first statement in the file. It tells Vim to interpret the |
947 script in its own namespace, instead of the global namespace. If a file | 958 script in its own namespace, instead of the global namespace. If a file |
948 starts with: > | 959 starts with: > |
949 vim9script | 960 vim9script |