mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
Update runtime files.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
*eval.txt* For Vim version 8.2. Last change: 2020 Sep 25
|
||||
*eval.txt* For Vim version 8.2. Last change: 2020 Oct 05
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@@ -897,7 +897,7 @@ Example: >
|
||||
All expressions within one level are parsed from left to right.
|
||||
|
||||
|
||||
expr1 *expr1* *trinary* *falsy-operator* *E109*
|
||||
expr1 *expr1* *trinary* *falsy-operator* *??* *E109*
|
||||
-----
|
||||
|
||||
The trinary operator: expr2 ? expr1 : expr1
|
||||
@@ -3503,7 +3503,7 @@ byteidxcomp({expr}, {nr}) *byteidxcomp()*
|
||||
< The first and third echo result in 3 ('e' plus composing
|
||||
character is 3 bytes), the second echo results in 1 ('e' is
|
||||
one byte).
|
||||
Only works different from byteidx() when 'encoding' is set to
|
||||
Only works differently from byteidx() when 'encoding' is set to
|
||||
a Unicode encoding.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
|
@@ -1,4 +1,4 @@
|
||||
*index.txt* For Vim version 8.2. Last change: 2020 May 31
|
||||
*index.txt* For Vim version 8.2. Last change: 2020 Oct 05
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@@ -784,10 +784,10 @@ tag char note action in Normal mode ~
|
||||
lines down
|
||||
|gk| gk 1 like "k", but when 'wrap' on go N screen
|
||||
lines up
|
||||
|gn| gn 1,2 find the next match with the last used
|
||||
search pattern and Visually select it
|
||||
|gm| gm 1 go to character at middle of the screenline
|
||||
|gM| gM 1 go to character at middle of the text line
|
||||
|gn| gn 1,2 find the next match with the last used
|
||||
search pattern and Visually select it
|
||||
|go| go 1 cursor to byte N in the buffer
|
||||
|gp| ["x]gp 2 put the text [from register x] after the
|
||||
cursor N times, leave the cursor after it
|
||||
@@ -1317,6 +1317,7 @@ tag command action ~
|
||||
|:filetype| :filet[ype] switch file type detection on/off
|
||||
|:filter| :filt[er] filter output of following command
|
||||
|:find| :fin[d] find file in 'path' and edit it
|
||||
|:final| :final declare an immutable variable in Vim9
|
||||
|:finally| :fina[lly] part of a :try command
|
||||
|:finish| :fini[sh] quit sourcing a Vim script
|
||||
|:first| :fir[st] go to the first file in the argument list
|
||||
@@ -1691,6 +1692,7 @@ tag command action ~
|
||||
|:unsilent| :uns[ilent] run a command not silently
|
||||
|:update| :up[date] write buffer if modified
|
||||
|:vglobal| :v[global] execute commands for not matching lines
|
||||
|:var| :var variable declaration in Vim9
|
||||
|:version| :ve[rsion] print version number and other info
|
||||
|:verbose| :verb[ose] execute command with 'verbose' set
|
||||
|:vertical| :vert[ical] make following command split vertically
|
||||
|
@@ -1,4 +1,4 @@
|
||||
*map.txt* For Vim version 8.2. Last change: 2020 Sep 09
|
||||
*map.txt* For Vim version 8.2. Last change: 2020 Oct 07
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@@ -252,6 +252,17 @@ For abbreviations |v:char| is set to the character that was typed to trigger
|
||||
the abbreviation. You can use this to decide how to expand the {lhs}. You
|
||||
should not either insert or change the v:char.
|
||||
|
||||
In case you want the mapping to not do anything, you can have the expression
|
||||
evaluate to an empty string. If something changed that requires Vim to
|
||||
go through the main loop (e.g. to update the display), return "\<Ignore>".
|
||||
This is similar to "nothing" but makes Vim return from the loop that waits for
|
||||
input. Example: >
|
||||
func s:OpenPopup()
|
||||
call popup_create(... arguments ...)
|
||||
return "\<Ignore>"
|
||||
endfunc
|
||||
nnoremap <expr> <F3> <Sid>OpenPopup()
|
||||
|
||||
Be very careful about side effects! The expression is evaluated while
|
||||
obtaining characters, you may very well make the command dysfunctional.
|
||||
For this reason the following is blocked:
|
||||
|
@@ -1,4 +1,4 @@
|
||||
*options.txt* For Vim version 8.2. Last change: 2020 Sep 15
|
||||
*options.txt* For Vim version 8.2. Last change: 2020 Oct 10
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@@ -2554,7 +2554,7 @@ A jump table for the options with a short description can be found at |Q_op|.
|
||||
"x" delete each combining character on its own. When it is off (the
|
||||
default) the character along with its combining characters are
|
||||
deleted.
|
||||
Note: When 'delcombine' is set "xx" may work different from "2x"!
|
||||
Note: When 'delcombine' is set "xx" may work differently from "2x"!
|
||||
|
||||
This is useful for Arabic, Hebrew and many other languages where one
|
||||
may have combining characters overtop of base characters, and want
|
||||
@@ -4682,7 +4682,7 @@ A jump table for the options with a short description can be found at |Q_op|.
|
||||
characters. Example: "abc;ABC"
|
||||
Example: "aA,fgh;FGH,cCdDeE"
|
||||
Special characters need to be preceded with a backslash. These are
|
||||
";", ',' and backslash itself.
|
||||
";", ',', '"', '|' and backslash itself.
|
||||
|
||||
This will allow you to activate vim actions without having to switch
|
||||
back and forth between the languages. Your language characters will
|
||||
|
@@ -1,4 +1,4 @@
|
||||
*repeat.txt* For Vim version 8.2. Last change: 2020 Aug 15
|
||||
*repeat.txt* For Vim version 8.2. Last change: 2020 Oct 09
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@@ -271,6 +271,9 @@ For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
|
||||
directories are added to 'runtimepath'. This is
|
||||
useful in your .vimrc. The plugins will then be
|
||||
loaded during initialization, see |load-plugins|.
|
||||
Note that for ftdetect scripts to be loaded
|
||||
you will need to write `filetype plugin indent on`
|
||||
AFTER all `packadd!` commands.
|
||||
|
||||
Also see |pack-add|.
|
||||
{only available when compiled with |+eval|}
|
||||
|
@@ -2447,6 +2447,7 @@ $VIM_POSIX vi_diff.txt /*$VIM_POSIX*
|
||||
:filter various.txt /*:filter*
|
||||
:fin editing.txt /*:fin*
|
||||
:fina eval.txt /*:fina*
|
||||
:final vim9.txt /*:final*
|
||||
:finally eval.txt /*:finally*
|
||||
:find editing.txt /*:find*
|
||||
:fini repeat.txt /*:fini*
|
||||
@@ -3371,6 +3372,7 @@ $VIM_POSIX vi_diff.txt /*$VIM_POSIX*
|
||||
:up editing.txt /*:up*
|
||||
:update editing.txt /*:update*
|
||||
:v repeat.txt /*:v*
|
||||
:var vim9.txt /*:var*
|
||||
:ve various.txt /*:ve*
|
||||
:ver various.txt /*:ver*
|
||||
:verb various.txt /*:verb*
|
||||
@@ -3689,6 +3691,7 @@ $VIM_POSIX vi_diff.txt /*$VIM_POSIX*
|
||||
>where repeat.txt /*>where*
|
||||
? pattern.txt /*?*
|
||||
?<CR> pattern.txt /*?<CR>*
|
||||
?? eval.txt /*??*
|
||||
@ repeat.txt /*@*
|
||||
@/ change.txt /*@\/*
|
||||
@: repeat.txt /*@:*
|
||||
@@ -6328,6 +6331,8 @@ extensions-improvements todo.txt /*extensions-improvements*
|
||||
f motion.txt /*f*
|
||||
false vim9.txt /*false*
|
||||
false-variable eval.txt /*false-variable*
|
||||
falsy eval.txt /*falsy*
|
||||
falsy-operator eval.txt /*falsy-operator*
|
||||
faq intro.txt /*faq*
|
||||
farsi farsi.txt /*farsi*
|
||||
farsi.txt farsi.txt /*farsi.txt*
|
||||
@@ -9656,6 +9661,7 @@ trojan-horse starting.txt /*trojan-horse*
|
||||
true vim9.txt /*true*
|
||||
true-variable eval.txt /*true-variable*
|
||||
trunc() eval.txt /*trunc()*
|
||||
truthy eval.txt /*truthy*
|
||||
try-conditionals eval.txt /*try-conditionals*
|
||||
try-echoerr eval.txt /*try-echoerr*
|
||||
try-finally eval.txt /*try-finally*
|
||||
|
@@ -1,4 +1,4 @@
|
||||
*todo.txt* For Vim version 8.2. Last change: 2020 Sep 28
|
||||
*todo.txt* For Vim version 8.2. Last change: 2020 Oct 10
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@@ -38,26 +38,13 @@ browser use: https://github.com/vim/vim/issues/1234
|
||||
*known-bugs*
|
||||
-------------------- Known bugs and current work -----------------------
|
||||
|
||||
Popup windows: don't send any keys from ":normal" to popup filter?
|
||||
Can drop ex_normal_busy_done then.
|
||||
|
||||
Move Test_let_* from test_vim9_script to test_vim9_assign
|
||||
|
||||
Modifiers in GTK: issue #6457. CTRL-6 should work, like CTRL-@ and CTRL-_.
|
||||
|
||||
3 October: remove using :let in Vim9 script.
|
||||
|
||||
Go back to not using string/list/dict as falsy/thruthy boolean?
|
||||
or only make "||" and "&&" result in a boolean?
|
||||
Making everything work:
|
||||
- If a function is defined in a block it may need to keep the block-locals,
|
||||
like a compiled closure.
|
||||
- Fix memory leaks in test_vim9_assign, remove "if 0"
|
||||
- Fix memory leaks in test_vim9_script
|
||||
- At the Vim9 script level, keep script variables local to the block they are
|
||||
declared in, like in Javascript (using :let).
|
||||
-> Need to remember what variables were declared and delete them when
|
||||
leaving the block.
|
||||
-> if a function is defined it may need to keep the block-locals
|
||||
Then Implement { } block at the script level.
|
||||
- Closure arguments should be more strict, like any function call?
|
||||
- Remove v:disallow_let
|
||||
- Recognize call to assert_fails() and execute it in the function context?
|
||||
Won't work if the command itself fails, not an expression failure:
|
||||
assert_fails("unknown", "E99:")
|
||||
@@ -70,10 +57,15 @@ Making everything work:
|
||||
did_catch = true
|
||||
endtry
|
||||
assert_true('did_catch')
|
||||
Add a new command,
|
||||
Add a new command perhaps:
|
||||
assertfail
|
||||
unknown
|
||||
endassertfail E99:.*unknown
|
||||
- Make map() give an error if the resulting type is wrong.
|
||||
Add mapnew() or mapcopy() to create a new List/Dict for the result, which
|
||||
can have a different value type.
|
||||
- Error message for "'yes && 0" is "using String as a Number", should be "using
|
||||
String as a Bool".
|
||||
- Run the same tests in :def and Vim9 script, like in Test_expr7_not()
|
||||
- In autocmd: use legacy syntax, not whatever the current script uses?
|
||||
- need to check type when a declaration specifies a type: #6507
|
||||
@@ -86,9 +78,6 @@ Making everything work:
|
||||
Also "list[0] += value". test in Test_assign_dict_unknown_type().
|
||||
- ":put" with ISN_PUT does not handle range correctly, e.g. ":$-2put".
|
||||
Add command to parse range at runtime?
|
||||
- Make map() give an error if the resulting type is wrong.
|
||||
Add mapnew() to create a new List/Dict for the result, which can have a
|
||||
different value type.
|
||||
- When defining an :autocmd or :command, how to specify using Vim9 syntax?
|
||||
- always do this when defined in a Vim9 script
|
||||
- add some command modifier.
|
||||
@@ -183,6 +172,11 @@ Further improvements:
|
||||
- compile "expr" and "call" expression of a channel in channel_exe_cmd()?
|
||||
|
||||
Popup windows:
|
||||
- Add a flag to make a popup window focusable?
|
||||
CTRL-W P cycle over any preview window or focusable popup, end up back in
|
||||
current window.
|
||||
? - switch between current window and all popup windows
|
||||
Esc in popup window goes back to previous current window
|
||||
- Cursor not updated before a redraw, making it jump. (#5943)
|
||||
- Add a termcap entry for changing the cursor when it goes under the popup and
|
||||
back. like t_SI and t_EI (t_SU and t_EU, where "U" means under?)
|
||||
@@ -291,6 +285,11 @@ Terminal emulator window:
|
||||
|
||||
Error numbers available: E653
|
||||
|
||||
Mapping with partial match not executed properly in GTK. (Ingo Karkat, #7082)
|
||||
|
||||
Patch for Template string: #4634
|
||||
Have another look at the implementation.
|
||||
|
||||
Patch to implement the vimtutor with a plugin: #6414
|
||||
Was originally written by Felipe Morales.
|
||||
|
||||
@@ -303,6 +302,16 @@ with 'termguicolors'. #1740
|
||||
|
||||
Patch for blockwise paste reporting changes: #6660.
|
||||
|
||||
Add an option to not fetch terminal codes in xterm, to avoid flicker when t_Co
|
||||
changes.
|
||||
|
||||
Add an option to start_timer() to return from the input loop with K_IGNORE.
|
||||
This is useful e.g. when a popup was created that disables mappings, we need
|
||||
to return from vgetc() to make this happen. #7011
|
||||
|
||||
Making breakat support multibyte characters (Yasuhiro Matsumoto, #6598)
|
||||
Scroll doesn't work correctly, why?
|
||||
|
||||
Expanding <mods> should put the tab number from cmdmod.tab before "tab".
|
||||
Any way to convert "$" back by using a special value? (#6901)
|
||||
|
||||
@@ -331,15 +340,16 @@ autocommands for the buffer lifecycle:
|
||||
BufIsRenamed (after buffer ID gets another name)
|
||||
The buffer list and windows are locked, no changes possible
|
||||
|
||||
Make it possible to map (console and GUI): #6457
|
||||
<C-[> 0x27 or is this <Esc> ?
|
||||
<C-\> 0x28
|
||||
<C-]> 0x29
|
||||
<C-^> 0x30
|
||||
<C-_> 0x31
|
||||
Matchparen doesn't remove highlight after undo. (#7054)
|
||||
Is OK when syntax HL is active.
|
||||
|
||||
Patch for Template string: #4634
|
||||
Have another look at the implementation.
|
||||
Currently Del can be used to delete the last character of a typed count.
|
||||
Can it also be used to delete an incomplete Normal mode command? (#7096)
|
||||
After an operator: should work. After "a" or "i" for text objects: should
|
||||
work.
|
||||
|
||||
Using "au!" after "filetype on" is a bit slow. Can the matching of
|
||||
autocommands be made faster? (#7056)
|
||||
|
||||
Valgrind warns for uninitialized values in f_term_dumpwrite().
|
||||
|
||||
@@ -538,6 +548,7 @@ Crash when mixing matchadd and substitute()? (Max Christian Pohle, 2018 May
|
||||
13, #2910) Can't reproduce?
|
||||
|
||||
Display messed up with matchparen, wrapping and scrolling. (#5638)
|
||||
Screen update bug related to matchparen. (Chris Heath, 2017 Mar 4, #1532)
|
||||
|
||||
When getting a focus event halfway a mapping this aborts the mapping. E.g.
|
||||
when "qq" is mapped and after the first "q" the mouse is moved outside of the
|
||||
@@ -1263,8 +1274,6 @@ GTK: When adding a timer from 'balloonexpr' it won't fire, because
|
||||
g_main_context_iteration() doesn't return. Need to trigger an event when the
|
||||
timer expires.
|
||||
|
||||
Screen update bug related to matchparen. (Chris Heath, 2017 Mar 4, #1532)
|
||||
|
||||
Rule to use "^" for statusline does not work if a space is defined with
|
||||
highlighting for both stl and stlnc. Patch by Ken Hamada (itchyny, 2016 Dec 11)
|
||||
|
||||
@@ -1497,8 +1506,6 @@ Have a way to get the call stack, in a function and from an exception.
|
||||
Second problem in #966: ins_compl_add_tv() uses get_dict_string() multiple
|
||||
times, overwrites the one buffer. (Nikolay Pavlov, 2016 Aug 5)
|
||||
|
||||
Filetype plugin for awk. (Doug Kearns, 2016 Sep 5)
|
||||
|
||||
Patch to improve map documentation. Issue #799.
|
||||
|
||||
We can use '. to go to the last change in the current buffer, but how about
|
||||
@@ -1718,8 +1725,6 @@ Extended file attributes lost on write (backupcopy=no). Issue 306.
|
||||
Patch to add :lockjumps. (Carlo Baldassi, 2015 May 25)
|
||||
OK to not block marks?
|
||||
|
||||
Mixup of highlighting when there is a match and SpellBad. (ZyX, 2015 Jan 1)
|
||||
|
||||
Patch on Issue 72: 'autochdir' causes problems for :vimgrep.
|
||||
|
||||
When two SIGWINCH arrive very quickly, the second one may be lost.
|
||||
@@ -1786,14 +1791,6 @@ arguments.
|
||||
|
||||
Problem with transparent and matchgroup. Issue #475
|
||||
|
||||
Spell files use a latin single quote. Unicode also has another single quote:
|
||||
0x2019. (Ron Aaron, 2014 Apr 4)
|
||||
New OpenOffice spell files support this with ICONV. But they are not
|
||||
compatible with Vim spell files. The old files can no longer be downloaded.
|
||||
|
||||
Spell checking: Add a feature to only consider two spaces after a dot to start
|
||||
a new sentence. Don't give the capitalization error when there is one space.
|
||||
|
||||
Idea: For a window in the middle (has window above and below it), use
|
||||
right-mouse-drag on the status line to move a window up/down without changing
|
||||
its height? It's like dragging the status bar above it at the same time.
|
||||
@@ -2468,9 +2465,6 @@ Don't load macmap.vim on startup, turn it into a plugin. (Ron Aaron,
|
||||
|
||||
Add "no_hlsearch" to winsaveview().
|
||||
|
||||
Cursorline highlighting combines with Search ('hlsearch') but not with
|
||||
SpellBad. (Jim Karsten, 2009 Mar 18)
|
||||
|
||||
When 'foldmethod' is "indent", adding an empty line below a fold and then
|
||||
indented text, creates a new fold instead of joining it with the previous one.
|
||||
(Evan Laforge, 2009 Oct 17)
|
||||
@@ -2977,12 +2971,6 @@ the Visual area. Can this be fixed? (James Vega, 2006 Sept 15)
|
||||
|
||||
GUI: When combining fg en bg make sure they are not equal.
|
||||
|
||||
Spell checking: Add a way to specify punctuation characters. Add the
|
||||
superscript numbers by default: 0x2070, 0xb9, 0xb2, 0xb3, 0x2074 - 0x2079.
|
||||
|
||||
Spell checking in popup menu: If the only problem is the case of the first
|
||||
character, don't offer "ignore" and "add to word list".
|
||||
|
||||
Use different pt_br dictionary for spell checking. (Jackson A. Aquino, 2006
|
||||
Jun 5)
|
||||
|
||||
@@ -2996,10 +2984,6 @@ Jul 22)
|
||||
|
||||
There should be something about spell checking in the user manual.
|
||||
|
||||
Spell menu: When using the Popup menu to select a replacement word,
|
||||
":spellrepeat" doesn't work. SpellReplace() uses setline(). Can it use "z="
|
||||
somehow? Or use a new function.
|
||||
|
||||
Mac: Using gvim: netrw window disappears. (Nick Lo, 2006 Jun 21)
|
||||
|
||||
Add an option to specify the character to use when a double-width character is
|
||||
@@ -3283,6 +3267,29 @@ Better 'rightleft' or BIDI support:
|
||||
- Minimal Vi with bidi support: https://github.com/aligrudi/neatvi
|
||||
By Ali Gholami Rudi, also worked on arabic.c
|
||||
|
||||
|
||||
Spell checking:
|
||||
- When 'cursorline' is set and the first word should have SpellCap
|
||||
highlighting, redrawing the line removes it when moving the cursor away
|
||||
from the line. (#7085) Would need to inspect the end of the previous line
|
||||
and update "capcol_lnum" and "cap_col".
|
||||
- Mixup of highlighting when there is a match and SpellBad. (ZyX, 2015 Jan 1)
|
||||
- Spell files use a latin single quote. Unicode also has another single
|
||||
quote: 0x2019. (Ron Aaron, 2014 Apr 4)
|
||||
New OpenOffice spell files support this with ICONV. But they are not
|
||||
compatible with Vim spell files. The old files can no longer be
|
||||
downloaded.
|
||||
- Add a feature to only consider two spaces after a dot to start a new
|
||||
sentence. Don't give the capitalization error when there is one space.
|
||||
- Add a way to specify punctuation characters. Add the superscript numbers
|
||||
by default: 0x2070, 0xb9, 0xb2, 0xb3, 0x2074 - 0x2079.
|
||||
- In popup menu: If the only problem is the case of the first character,
|
||||
don't offer "ignore" and "add to word list".
|
||||
- Spell menu: When using the Popup menu to select a replacement word,
|
||||
":spellrepeat" doesn't work. SpellReplace() uses setline(). Can it use
|
||||
"z=" somehow? Or use a new function.
|
||||
|
||||
|
||||
Quickfix/Location List:
|
||||
- Window size is wrong when using quickfix window. (Lifepillar, 2018 Aug 24,
|
||||
#2999)
|
||||
|
@@ -48515,7 +48515,7 @@ Solution: Recognize true and false.
|
||||
Files: src/eval.c, src/testdir/test_vim9_expr.vim
|
||||
|
||||
Patch 8.2.1205
|
||||
Problem: Vim9: && and || work different when not compiled.
|
||||
Problem: Vim9: && and || work differently when not compiled.
|
||||
Solution: Keep the value.
|
||||
Files: src/eval.c, src/testdir/test_vim9_expr.vim
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
*vim9.txt* For Vim version 8.2. Last change: 2020 Sep 26
|
||||
*vim9.txt* For Vim version 8.2. Last change: 2020 Oct 05
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@@ -164,12 +164,12 @@ the "name#" prefix is sufficient. >
|
||||
|
||||
When using `:function` or `:def` to specify a nested function inside a `:def`
|
||||
function, 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
|
||||
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.
|
||||
|
||||
When referring to a function and no "s:" or "g:" prefix is used, Vim will
|
||||
search for the function:
|
||||
- in the function scope
|
||||
- in the function scope, in block scopes
|
||||
- in the script scope, possibly imported
|
||||
- in the list of global functions
|
||||
However, it is recommended to always use "g:" to refer to a global function
|
||||
@@ -1140,7 +1140,7 @@ Two alternatives were considered:
|
||||
def Func(arg1 number, arg2 string) bool
|
||||
|
||||
The first is more familiar for anyone used to C or Java. The second one
|
||||
doesn't really has an advantage over the first, so let's discard the second.
|
||||
doesn't really have an advantage over the first, so let's discard the second.
|
||||
|
||||
Since we use type inference the type can be left out when it can be inferred
|
||||
from the value. This means that after `var` we don't know if a type or a name
|
||||
@@ -1155,19 +1155,35 @@ declaration.
|
||||
|
||||
Expressions ~
|
||||
|
||||
Expression evaluation was already close to what JavaScript and other languages
|
||||
are doing. Some details are unexpected and can be fixed. For example how the
|
||||
|| and && operators work. Legacy Vim script: >
|
||||
var value = 44
|
||||
...
|
||||
var result = value || 0 # result == 1
|
||||
Expression evaluation was already close to what other languages are doing.
|
||||
Some details are unexpected and can be improved. For example a boolean
|
||||
condition would accept a string, convert it to a number and check if the
|
||||
number is non-zero. This is unexpected and often leads to mistakes, since
|
||||
text not starting with a number would be converted to zero, which is
|
||||
considered false. Thus a string would not give an error and be considered
|
||||
false if it doesn't start with a number. That is confusing.
|
||||
|
||||
Vim9 script works like JavaScript/TypeScript, keep the value: >
|
||||
var value = 44
|
||||
...
|
||||
var result = value || 0 # result == 44
|
||||
In Vim9 type checking is more strict to avoid mistakes. Where a condition is
|
||||
used, e.g. with the `:if` command and the `||` operator, only boolean-like
|
||||
values are accepted:
|
||||
true: `true`, `v:true`, `1`, `0 < 9`
|
||||
false: `false`, `v:false`, `0`, `0 > 9`
|
||||
Note that the number zero is false and the number one is true. This is more
|
||||
persmissive than most other languages. It was done because many builtin
|
||||
functions return these values.
|
||||
|
||||
TODO: the semantics of || and && need to be reconsidered.
|
||||
If you have any type of value and want to use it as a boolean, use the `!!`
|
||||
operator:
|
||||
true: !`!'text'`, `!![99]`, `!!{'x': 1}`, `!!99`
|
||||
false: `!!''`, `!![]`, `!!{}`
|
||||
|
||||
From a language like JavaScript we have this handy construct: >
|
||||
GetName() || 'unknown'
|
||||
However, this conflicts with only allowing a boolean for a condition.
|
||||
Therefore the "??" operator was added: >
|
||||
GetName() ?? 'unknown'
|
||||
Here you can explicitly express your intention to use the value as-is and not
|
||||
result in a boolean. This is called the |falsy-operator|.
|
||||
|
||||
|
||||
Import and Export ~
|
||||
|
Reference in New Issue
Block a user