*eval.txt* Nvim
VIM REFERENCE MANUAL by Bram Moolenaar
Expression evaluation *expression* *expr* *E15* *eval*
Using expressions is introduced in chapter 41 of the user manual |usr_41.txt|.
Type |gO| to see the table of contents.
==============================================================================
1. Variables *variables*
1.1 Variable types ~
*E712*
There are six types of variables:
*Number* *Integer*
Number A 32 or 64 bit signed number. |expr-number|
The number of bits is available in |v:numbersize|.
Examples: -123 0x10 0177 0b1011
Float A floating point number. |floating-point-format| *Float*
Examples: 123.456 1.15e-6 -1.1e3
*E928*
String A NUL terminated string of 8-bit unsigned characters (bytes).
|expr-string| Examples: "ab\txx\"--" 'x-z''a,c'
Funcref A reference to a function |Funcref|.
Example: function("strlen")
It can be bound to a dictionary and arguments, it then works
like a Partial.
Example: function("Callback", [arg], myDict)
List An ordered sequence of items |List|.
Example: [1, 2, ['a', 'b']]
Dictionary An associative, unordered array: Each entry has a key and a
value. |Dictionary|
Examples:
{'blue': "#0000ff", 'red': "#ff0000"}
#{blue: "#0000ff", red: "#ff0000"}
The Number and String types are converted automatically, depending on how they
are used.
Conversion from a Number to a String is by making the ASCII representation of
the Number. Examples:
Number 123 --> String "123" ~
Number 0 --> String "0" ~
Number -1 --> String "-1" ~
*octal*
Conversion from a String to a Number is done by converting the first digits to
a number. Hexadecimal "0xf9", Octal "017", and Binary "0b10" numbers are
recognized. If the String doesn't start with digits, the result is zero.
Examples:
String "456" --> Number 456 ~
String "6bar" --> Number 6 ~
String "foo" --> Number 0 ~
String "0xf1" --> Number 241 ~
String "0100" --> Number 64 ~
String "0b101" --> Number 5 ~
String "-8" --> Number -8 ~
String "+8" --> Number 0 ~
To force conversion from String to Number, add zero to it: >
:echo "0100" + 0
< 64 ~
To avoid a leading zero to cause octal conversion, or for using a different
base, use |str2nr()|.
*TRUE* *FALSE* *Boolean*
For boolean operators Numbers are used. Zero is FALSE, non-zero is TRUE.
You can also use |v:false| and |v:true|.
When TRUE is returned from a function it is the Number one, FALSE is the
number zero.
Note that in the command: >
:if "foo"
:" NOT executed
"foo" is converted to 0, which means FALSE. If the string starts with a
non-zero number it means TRUE: >
:if "8foo"
:" executed
To test for a non-empty string, use empty(): >
:if !empty("foo")
<
*non-zero-arg*
Function arguments often behave slightly different from |TRUE|: If the
argument is present and it evaluates to a non-zero Number, |v:true| or a
non-empty String, then the value is considered to be TRUE.
Note that " " and "0" are also non-empty strings, thus considered to be TRUE.
A List, Dictionary or Float is not a Number or String, thus evaluate to FALSE.
*E745* *E728* *E703* *E729* *E730* *E731*
|List|, |Dictionary|, |Funcref|, and |Blob| types are not automatically
converted.
*E805* *E806* *E808*
When mixing Number and Float the Number is converted to Float. Otherwise
there is no automatic conversion of Float. You can use str2float() for String
to Float, printf() for Float to String and float2nr() for Float to Number.
*E891* *E892* *E893* *E894*
When expecting a Float a Number can also be used, but nothing else.
*no-type-checking*
You will not get an error if you try to change the type of a variable.
1.2 Function references ~
*Funcref* *E695* *E718*
A Funcref variable is obtained with the |function()| function, the |funcref()|
function or created with the lambda expression |expr-lambda|. It can be used
in an expression in the place of a function name, before the parenthesis
around the arguments, to invoke the function it refers to. Example: >
:let Fn = function("MyFunc")
:echo Fn()
< *E704* *E705* *E707*
A Funcref variable must start with a capital, "s:", "w:", "t:" or "b:". You
can use "g:" but the following name must still start with a capital. You
cannot have both a Funcref variable and a function with the same name.
A special case is defining a function and directly assigning its Funcref to a
Dictionary entry. Example: >
:function dict.init() dict
: let self.val = 0
:endfunction
The key of the Dictionary can start with a lower case letter. The actual
function name is not used here. Also see |numbered-function|.
A Funcref can also be used with the |:call| command: >
:call Fn()
:call dict.init()
The name of the referenced function can be obtained with |string()|. >
:let func = string(Fn)
You can use |call()| to invoke a Funcref and use a list variable for the
arguments: >
:let r = call(Fn, mylist)
<
*Partial*
A Funcref optionally binds a Dictionary and/or arguments. This is also called
a Partial. This is created by passing the Dictionary and/or arguments to
function() or funcref(). When calling the function the Dictionary and/or
arguments will be passed to the function. Example: >
let Cb = function('Callback', ['foo'], myDict)
call Cb('bar')
This will invoke the function as if using: >
call myDict.Callback('foo', 'bar')
Note that binding a function to a Dictionary also happens when the function is
a member of the Dictionary: >
let myDict.myFunction = MyFunction
call myDict.myFunction()
Here MyFunction() will get myDict passed as "self". This happens when the
"myFunction" member is accessed. When assigning "myFunction" to otherDict
and calling it, it will be bound to otherDict: >
let otherDict.myFunction = myDict.myFunction
call otherDict.myFunction()
Now "self" will be "otherDict". But when the dictionary was bound explicitly
this won't happen: >
let myDict.myFunction = function(MyFunction, myDict)
let otherDict.myFunction = myDict.myFunction
call otherDict.myFunction()
Here "self" will be "myDict", because it was bound explicitly.
1.3 Lists ~
*list* *List* *Lists* *E686*
A List is an ordered sequence of items. An item can be of any type. Items
can be accessed by their index number. Items can be added and removed at any
position in the sequence.
List creation ~
*E696* *E697*
A List is created with a comma separated list of items in square brackets.
Examples: >
:let mylist = [1, two, 3, "four"]
:let emptylist = []
An item can be any expression. Using a List for an item creates a
List of Lists: >
:let nestlist = [[11, 12], [21, 22], [31, 32]]
An extra comma after the last item is ignored.
List index ~
*list-index* *E684*
An item in the List can be accessed by putting the index in square brackets
after the List. Indexes are zero-based, thus the first item has index zero. >
:let item = mylist[0] " get the first item: 1
:let item = mylist[2] " get the third item: 3
When the resulting item is a list this can be repeated: >
:let item = nestlist[0][1] " get the first list, second item: 12
<
A negative index is counted from the end. Index -1 refers to the last item in
the List, -2 to the last but one item, etc. >
:let last = mylist[-1] " get the last item: "four"
To avoid an error for an invalid index use the |get()| function. When an item
is not available it returns zero or the default value you specify: >
:echo get(mylist, idx)
:echo get(mylist, idx, "NONE")
List concatenation ~
Two lists can be concatenated with the "+" operator: >
:let longlist = mylist + [5, 6]
:let mylist += [7, 8]
To prepend or append an item turn the item into a list by putting [
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
neovim软件便携包 (1602个子文件)
nvim.1 9KB
makehtml.awk 18KB
maketags.awk 909B
less.bat 300B
curl-ca-bundle.crt 202KB
nvim.desktop 4KB
logtalk.dict 3KB
opengl32sw.dll 15.25MB
Qt5Gui.dll 6.2MB
Qt5Widgets.dll 5.96MB
Qt5Core.dll 5.94MB
D3Dcompiler_47.dll 3.31MB
libGLESV2.dll 2.68MB
qwindows.dll 1.82MB
Qt5Network.dll 1.72MB
libstdc++-6.dll 1.47MB
winpty.dll 625KB
qtiff.dll 498KB
lua51.dll 492KB
qwebp.dll 449KB
c.dll 408KB
Qt5Svg.dll 352KB
qjpeg.dll 323KB
uv.dll 270KB
qwindowsvistastyle.dll 192KB
libgcc_s_dw2-1.dll 118KB
qgenericbearer.dll 88KB
libwinpthread-1.dll 78KB
msgpackc.dll 52KB
qicns.dll 45KB
qsvgicon.dll 43KB
qico.dll 35KB
qgif.dll 33KB
qsvg.dll 27KB
qtga.dll 26KB
qwbmp.dll 25KB
libEGL.dll 22KB
curl.exe 4.35MB
nvim.exe 4.08MB
nvim-qt.exe 3.35MB
win32yank.exe 891KB
winpty-agent.exe 711KB
xxd.exe 70KB
diff.exe 67KB
tee.exe 58KB
vim-01-beginner.tutor.json 2KB
tutor.tutor.json 1KB
util.lua 68KB
lsp.lua 56KB
diagnostic.lua 43KB
protocol.lua 39KB
rpc.lua 22KB
_meta.lua 20KB
handlers.lua 18KB
buf.lua 18KB
query.lua 17KB
shared.lua 16KB
languagetree.lua 16KB
inspect.lua 10KB
_snippet.lua 10KB
highlighter.lua 8KB
codelens.lua 7KB
man.lua 5KB
log.lua 4KB
highlight.lua 3KB
uri.lua 3KB
treesitter.lua 3KB
language.lua 1KB
health.lua 1KB
F.lua 564B
compat.lua 532B
nvim.mo 254KB
nvim.mo 190KB
nvim.mo 184KB
nvim.mo 178KB
nvim.mo 174KB
nvim.mo 171KB
nvim.mo 167KB
nvim.mo 167KB
nvim.mo 157KB
nvim.mo 126KB
nvim.mo 124KB
nvim.mo 122KB
nvim.mo 120KB
nvim.mo 120KB
nvim.mo 118KB
nvim.mo 118KB
nvim.mo 111KB
nvim.mo 104KB
nvim.mo 104KB
nvim.mo 102KB
nvim.mo 102KB
nvim.mo 101KB
nvim.mo 99KB
nvim.mo 94KB
nvim.mo 80KB
nvim.mo 79KB
nvim.mo 71KB
nvim.mo 63KB
nvim.mo 63KB
共 1602 条
- 1
- 2
- 3
- 4
- 5
- 6
- 17
资源评论
Crayon112
- 粉丝: 115
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- pta题库答案c语言之树结构2ListLeaves.zip
- pta题库答案c语言之树结构1树的同构.zip
- 基于C++实现民航飞行与地图简易管理系统可执行程序+说明+详细注释.zip
- pta题库答案c语言之复杂度1最大子列和问题.zip
- 三维装箱问题(Three-Dimensional Bin Packing Problem,3D-BPP)是一个经典的组合优化问题
- 以下是一些关于Linux线程同步的基本概念和方法.txt
- 以下是一个简化的示例,它使用pygame库来模拟烟花动画的框架.txt
- Linux线程同步机制深度解析与实用指南.zip
- PTA题库C语言解题策略与实战.rar
- SVPWM控制技术的simulink建模与仿真【包括simulink模型,参考文献,操作步骤】
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功