May 24, 2021 Vim
In Vimscript, our first focus is
echo
and
echom
You can execute the
:help echo
:help echom
to view their help documentation.
After reading this book, when you encounter a new command again, you should first execute
:help
command to view its help documentation.
Experience the echo command by executing
echo
command:
:echo "Hello, world!"
You should see Hello,
Hello, world!
printed out.
Now let's execute the following command and
echom
command:
:echom "Hello again, world!"
You should see Hello
Hello again, world!
printed out.
Follow these commands to see the difference between the two print commands above:
:messages
You should see some news.
Hello, world!
Should not be in it, but
Hello again, world!
in
.
When you write more complex Vimscript, you may want to "print some information" to make it easier to debug the program.
:echo
command prints out, but once your script is running, that output disappears.
Information
:echom
is saved and you can perform
:messages
command to view that information again.
Before we move on, let's see how to add comments.
When you write a Vimscript script (in
~/.vimrc
any other file), you can add
"
through the " character, for example:
" Make space more useful
nnoremap <space> za
This annotation method isn't always effective (that's Vimscript's point of speechless), but more than that, it works. We'll talk later about what's going on and why it won't work.
Read
:help echo
help documentation.
Read
:help echom
help documentation.
Read
:help messages
help documentation.
Add a line of code to your
~/.vimrc
file so that each time Vim is opened, a cute ASCII character cat
>^.^<