Puedes definir variables inmutables con `const`. Al ser inmutables, una vez que a la variable se le asigna un valor, ya no puedes reasignarle un valor diferente más adelante.
Vim puede acceder a las variables de entorno de tu terminal. Por ejemplo, si tienes la variable `SHELL` de entorno en tu terminal, puedes acceder a ella desde Vim mediante:
Ahora cuando pegues el contenido del registro a (`"ap`), este mostrará el contenido que es "chocolate donut". El operador `.=` une dos cadenas. La expresión `let @a .= " donut"` es lo mismo que `let @a = @a . " donut"`
Una variable precedida de `b:` es una variable de *buffer*. Una variable de *buffer* es una variable que es local al *buffer* actual (ver capítulo 02). Si tienes múltiples *buffers* abiertos, cada *buffer* tendrá su propia lista separada de variables de *buffer*.
Si ejecutas `echo b:donut` en el *buffer* 1, mostrará "chocolate donut". Si ejecutas lo mismo pero ahora en el *buffer* 2, en este caso se mostrará "frambuesa donut".
Como nota complementaria, Vim tiene una variable de *buffer* "especial" `b:changedtick` que guarda el número acumulado de todos los cambios realizados en el *buffer* actual.
When you call `Consume`, you see it decrements the `s:dozen` value as expected. When you try to get `s:dozen` value directly, Vim won't find it because you are out of scope. `s:dozen` is only accessible from inside `dozen.vim`.
Each time you source the `dozen.vim` file, it resets the `s:dozen` counter. If you are in the middle of decrementing `s:dozen` value and you run `:source dozen.vim`, the counter resets back to 12. This can be a problem for unsuspecting users. To fix this issue, refactor the code:
```
if !exists("s:dozen")
let s:dozen = 12
endif
function Consume()
let s:dozen -= 1
echo s:dozen
endfunction
```
Now when you source `dozen.vim` while in the middle of decrementing, Vim reads `!exists("s:dozen")`, finds that it is true, and doesn't reset the value back to 12.
### Function Local And Function Formal Parameter variable
Both the function local variable (`l:`) and the function formal variable (`a:`) will be covered in the next chapter.
### Built-in Vim Variables
A variable prepended with `v:` is a special built-in Vim variable. You cannot define these variables. You have seen some of them already.
-`v:version` tells you what Vim version you are using.
-`v:key` contains the current item value when iterating through a dictionary.
-`v:val` contains the current item value when running a `map()` or `filter()` operation.
-`v:true`, `v:false`, `v:null`, and `v:none` are special data types.
There are other variables. For a list of Vim built-in variables, check out `:h vim-variable` or `:h v:`.
## Using Vim Variable Scopes The Smart Way
Being able to quickly access environment, option, and register variables give you a broad flexibility to customize your editor and terminal environment. You also learned that Vim has 9 different variable scopes, each existing under a certain constraints. You can take advantage of these unique variable types to decouple your program.
You made it this far. You learned about data types, means of combinations, and variable scopes. Only one thing is left: functions.