SpaceVim
A modular Vim/Neovim configuration
Home | About | Quick start guide | Documentation | Development | Community | Sponsors | 中文
Vim script is the built-in language used in Vim/Neovim editors.
Variables are “containers” for storing information. In vim script, a variable starts with the scoop, followed by the name of this variable.
let g:foo = 'hello world'
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
Powered by Jekyll