Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Vimscript variable scope


May 24, 2021 Vim


Table of contents


If you've used dynamic languages like Python or Ruby before, you're probably already familiar with the variables of the Vim script. You'll find that most of the Vim variable is the same as you think, but one thing that might be different is the scope of the variable.

Open two different files in two separate windows, and then execute the following command in one of the windows:

:let b:hello = "world"
:echo b:hello

As you wish, Vim will show world Now switch to another buffer and execute the echo again:

:echo b:hello

This time Vim throws an error that can't find a variable,

When you use b: in the b: this is equivalent to telling the Vim hello to be the local variable of the current buffer.

Vim has many different variable scopes, but we need to learn more about Vim scripting before we can use other type variable scopes. For now, you only need to remember that when a variable starts with a character and colon, it means that it is a scope variable.

Practice

Browse :help internal-variables First look, familiar with familiar, even if there is no understanding of the place does not matter.