How to execute Vimscript

Vimscript is made up of commands you run in command-line mode, and really is just a sequence of Vim commands in a file. You can always execute Vimscript by running each command in command mode (the one you prefix with :), or by executing the file with commands using a :source command. Historically, Vim scripts have a .vim extension.

As you're following along with this section, you may want to create *.vim files to experiment in. You can execute the files by running this:

:source <filename>

A much shorter version of that is this:

:so %

Here, :so is a short version of :source, and % refers to the currently open file.

For example, I just created a variables.vim file to play around with Vim's variables. I could execute its contents with :so %:

Alternatively, I could run each command in command mode. For example, if I wanted to print the contents of a variable, g:animal, I would run the following:

:echo g:animal

I will do just that, as in, print cat into our status line:

Normally, I run longer scripts with :so %, and perform debugging operations through command-line mode (:).

Additionally, if you're entering commands in command-line mode, you'll stay in command-line mode if you enter a function or a flow control operator (such as if, while, or for):

In this example, I did not have to type : on every line. Additionally, each line gets executed as you hit Enter (as you can see by this is probably unix being printed on the screen).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.247.196