SpaceVim
Vim 脚本是 Vim/Neovim 编辑器内置的脚本语言。可以用于配置 Vim/Neovim 及开发插件。
Vim 脚本注释都是以 双引号开头,比如:
" 这是一个单行注释
let g:foo = 1 " 这是一个行尾注释。
变量是一个存储数据的容器,在 vim 脚本内,一个变量由作用域前缀和变量名称组成,比如:
let g:foo = 'hello world'
其中,g:foo
就是一个变量,g:
就是一个作用域标识。foo
是这个变量的名称。
In vim script, there are 6 kinds of variable scopes:
g:
global variable scopes:
local to scriptl:
local to function, it can be prepended.w:
local to windowt:
local to tabb:
local to bufferOften when you write vim script, you want the same code block to run over and over again. Instead of adding several almost equal lines in the script, we can use loops.
In vim script there are two kinds of lools, for loop
and while loop
.
To execute a block of code a specified number of times, you need to use for loop. here is an example of for loop in vim script:
for n in range(10)
echo n
endfor
While loops execute a block of code while the specified condition is true.
Vim provides many built-in functions, besides the built-in functions, we can also create our own functions.
function! TestHello() abort
echo "hello world"
endfunction
use :call TestHello()
to run a function.
Within a function, we can use return statement to return a variable.
if the return statement is prepended. 0
is returned.
function! Test() abort
return 'hello'
endfunction
echo Test()
" hello
function! Test() abort
endfunction
echo Test()
" 0
由Jekyll强力驱动