Skip to content

Commit

Permalink
Proof 19-26.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjl committed Apr 4, 2013
1 parent d7a8727 commit b971c43
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 53 deletions.
20 changes: 10 additions & 10 deletions chapters/19.markdown
Expand Up @@ -14,14 +14,14 @@ the following commands:
:let foo = "bar"
:echo foo

Vim will display "bar". `foo` is now a variable, and we've assigned it
a string: "bar". Now run these commands:
Vim will display `bar`. `foo` is now a variable, and we've assigned it
a string: `"bar"`. Now run these commands:

:::vim
:let foo = 42
:echo foo

Vim will display "42", because we've reassigned `foo` to the integer "42".
Vim will display `42`, because we've reassigned `foo` to the integer `42`.

From these short examples it may seem like Vimscript is dynamically typed.
That's not the case, but we'll talk more about that later.
Expand All @@ -36,7 +36,7 @@ following commands:
:set textwidth=80
:echo &textwidth

Vim will display "80". Using an ampersand in front of a name tells Vim that
Vim will display `80`. Using an ampersand in front of a name tells Vim that
you're referring to the option, not a variable that happens to have the same
name.

Expand All @@ -46,13 +46,13 @@ Let's see how Vim works with boolean options. Run the following commands:
:set nowrap
:echo &wrap

Vim displays "0". Now try these commands:
Vim displays `0`. Now try these commands:

:::vim
:set wrap
:echo &wrap

This time Vim displays "1". This is a very strong hint that Vim treats the
This time Vim displays `1`. This is a very strong hint that Vim treats the
integer `0` as "false" and the integer `1` as "true". It would be reasonable to
assume that Vim treats *any* non-zero integer as "truthy", and this is indeed
the case.
Expand All @@ -64,7 +64,7 @@ following commands:
:let &textwidth = 100
:set textwidth?

Vim will display "textwidth=100".
Vim will display `textwidth=100`.

Why would we want to do this when we could just use `set`? Run the following
commands:
Expand All @@ -73,7 +73,7 @@ commands:
:let &textwidth = &textwidth + 10
:set textwidth?

This time Vim displays "textwidth=110". When you set an option using `set` you
This time Vim displays `textwidth=110`. When you set an option using `set` you
can only set it to a single literal value. When you use `let` and set it as
a variable you can use the full power of Vimscript to determine the value.

Expand Down Expand Up @@ -105,14 +105,14 @@ You can also read and set *registers* as variables. Run the following command:

Now put your cursor somewhere in your text and type `"ap`. This command tells
Vim to "paste the contents of register `a` here". We just set the contents of
that register, so Vim pastes "hello!" into your text.
that register, so Vim pastes `hello!` into your text.

Registers can also be read. Run the following command:

:::vim
:echo @a

Vim will echo "hello!".
Vim will echo `hello!`.

Select a word in your file and yank it with `y`, then run this command:

Expand Down
2 changes: 1 addition & 1 deletion chapters/20.markdown
Expand Up @@ -12,7 +12,7 @@ the following commands:
:let b:hello = "world"
:echo b:hello

As expected, Vim displays "world". Now switch to the other buffer and run the
As expected, Vim displays `world`. Now switch to the other buffer and run the
`echo` command again:

:::vim
Expand Down
10 changes: 5 additions & 5 deletions chapters/21.markdown
Expand Up @@ -45,15 +45,15 @@ Now that we've got that out of the way, run the following commands:
: echom "ONE"
:endif

Vim will display "ONE", because the integer `1` is "truthy". Now try these
Vim will display `ONE`, because the integer `1` is "truthy". Now try these
commands:

:::vim
:if 0
: echom "ZERO"
:endif

Vim will *not* display "ZERO" because the integer `0` is "falsy". Let's see how
Vim will *not* display `ZERO` because the integer `0` is "falsy". Let's see how
strings behave. Run these commands:

:::vim
Expand All @@ -80,8 +80,8 @@ To try to wrap our heads around what's going on, run the following three command
:echom "10hello" + 10
:echom "hello10" + 10

The first command causes Vim to echo "10", the second command echoes "20", and
the third echoes "10" again!
The first command causes Vim to echo `10`, the second command echoes `20`, and
the third echoes `10` again!

After observing all of these commands we can draw a few informed conclusions
about Vimscript:
Expand Down Expand Up @@ -109,7 +109,7 @@ commands:
: echom "finally!"
:endif

Vim echoes "finally!" because both of the previous conditions evaluate to zero,
Vim echoes `finally!` because both of the previous conditions evaluate to zero,
which is falsy.

Exercises
Expand Down
10 changes: 5 additions & 5 deletions chapters/22.markdown
Expand Up @@ -12,7 +12,7 @@ Run the following commands:
: echom "foo"
:endif

Vim will, of course, display "foo". Now run these commands:
Vim will, of course, display `foo`. Now run these commands:

:::vim
:if 10 > 2001
Expand All @@ -29,7 +29,7 @@ everything works as expected. Run these commands:
: echom "second"
:endif

Vim displays "second". Nothing surprising here. Let's try comparing strings.
Vim displays `second`. Nothing surprising here. Let's try comparing strings.
Run these commands:

:::vim
Expand All @@ -39,7 +39,7 @@ Run these commands:
: echom "two"
:endif

Vim echoes "two". There's still nothing surprising, so what was I going on
Vim echoes `two`. There's still nothing surprising, so what was I going on
about at the beginning of the chapter?

Case Sensitivity
Expand Down Expand Up @@ -97,7 +97,7 @@ Run the following commands:
: echom "second"
:endif

Vim displays "first" because `==?` is the "case-insensitive no matter what the
Vim displays `first` because `==?` is the "case-insensitive no matter what the
user has set" comparison operator. Now run the following commands:

:::vim
Expand All @@ -108,7 +108,7 @@ user has set" comparison operator. Now run the following commands:
: echom "two"
:endif

Vim displays "two" because `==#` is the "case-sensitive no matter what the user
Vim displays `two` because `==#` is the "case-sensitive no matter what the user
has set" comparison operator.

The moral of this story is that you should *always* use explicit case sensitive
Expand Down
8 changes: 4 additions & 4 deletions chapters/23.markdown
Expand Up @@ -31,7 +31,7 @@ This time Vim will happily define the function. Let's try running it:
:::vim
:call Meow()

Vim will display "Meow!" as expected.
Vim will display `Meow!` as expected.

Let's try returning a value. Run the following commands:

Expand All @@ -46,7 +46,7 @@ Now try it out by running this command:
:echom GetMeow()

Vim will call the function and give the result to `echom`, which will display
"Meow String!".
`Meow String!`.

Calling Functions
-----------------
Expand All @@ -61,7 +61,7 @@ following commands:
:call Meow()
:call GetMeow()

The first will display "Meow!" but the second doesn't display anything. The
The first will display `Meow!` but the second doesn't display anything. The
return value is thrown away when you use `call`, so this is only useful when the
function has side effects.

Expand All @@ -81,7 +81,7 @@ Run the following command:
:::vim
:echom Meow()

This will display two lines: "Meow!" and "0". The first obviously comes from
This will display two lines: `Meow!` and `0`. The first obviously comes from
the `echom` inside of `Meow`. The second shows us that if a Vimscript function
doesn't return a value, it implicitly returns `0`. Let's use this to our
advantage. Run the following commands:
Expand Down
12 changes: 6 additions & 6 deletions chapters/24.markdown
Expand Up @@ -14,7 +14,7 @@ Run the function:
:::vim
:call DisplayName("Your Name")

Vim will display two lines: "Hello! My name is:" and "Your Name".
Vim will display two lines: `Hello! My name is:` and `Your Name`.

Notice the `a:` in the name of the variable that we passed to the `echom`
command. This represents a variable scope, which we talked about in an earlier
Expand Down Expand Up @@ -56,12 +56,12 @@ This function shows us several things, so let's look at each one individually.
The `...` in the function definition tells Vim that this function can take any
number of arguments. This is like a `*args` argument in a Python function.

The first line of the function echoes the message `a:0` and displays "2". When
The first line of the function echoes the message `a:0` and displays `2`. When
you define a function that takes a variable number of arguments in Vim, `a:0`
will be set to the number of extra arguments you were given. In this case we
passed two arguments to `Varg` so Vim displayed "2".
passed two arguments to `Varg` so Vim displayed `2`.

The second line echoes `a:1` which displays "a". You can use `a:1`, `a:2`, etc
The second line echoes `a:1` which displays `a`. You can use `a:1`, `a:2`, etc
to refer to each extra argument your function receives. If we had used `a:2`
Vim would have displayed "b".

Expand All @@ -83,7 +83,7 @@ commands:

:call Varg2("a", "b", "c")

We can see that Vim puts "a" into the named argument `a:foo`, and the rest are
We can see that Vim puts `"a"` into the named argument `a:foo`, and the rest are
put into the list of varargs.

Assignment
Expand Down Expand Up @@ -111,7 +111,7 @@ these commands:

:call AssignGood("test")

This time the function works, and Vim displays "Yep".
This time the function works, and Vim displays `Yep`.

Exercises
---------
Expand Down
22 changes: 11 additions & 11 deletions chapters/25.markdown
Expand Up @@ -15,12 +15,12 @@ You can specify Numbers in a few different ways. Run the following command:
:::vim
:echom 100

No surprises here -- Vim displays "100". Now run this command:
No surprises here -- Vim displays `100`. Now run this command:

:::vim
:echom 0xff

This time Vim displays "255". You can specify numbers in hex notation by
This time Vim displays `255`. You can specify numbers in hex notation by
prefixing them with `0x` or `0X`. Now run this command:

:::vim
Expand All @@ -33,8 +33,8 @@ because it's easy to make mistakes. Try the following commands:
:echom 017
:echom 019

Vim will print "15" for the first command, because "17" in octal is equal to
"15" in decimal. For the second command Vim treats it as a decimal number, even
Vim will print `15` for the first command, because `17` in octal is equal to
`15` in decimal. For the second command Vim treats it as a decimal number, even
though it starts with a `0`, because it's not a valid octal number.

Because Vim silently does the wrong thing in this case, I'd recommend avoiding
Expand All @@ -51,24 +51,24 @@ Floats can also be specified in multiple ways. Run the following command:
Notice that we're using `echo` here and not `echom` like we usually to. We'll
talk about why in a moment.

Vim displays "100.1" as expected. You can also use exponential notation. Run
Vim displays `100.1` as expected. You can also use exponential notation. Run
this command:

:::vim
:echo 5.45e+3

Vim displays "5450.0". A negative exponent can also be used. Run this command:
Vim displays `5450.0`. A negative exponent can also be used. Run this command:

:::vim
:echo 15.45e-2

Vim displays "0.1545". The `+` or `-` before the power of ten is optional. If
Vim displays `0.1545`. The `+` or `-` before the power of ten is optional. If
it's omitted then it's assumed to be positive. Run the following command:

:::vim
:echo 15.3e9

Vim will display "1.53e10", which is equivalent. The decimal point and number
Vim will display `1.53e10`, which is equivalent. The decimal point and number
after it are *not* optional. Run the following command and see that it crashes:

:::vim
Expand All @@ -84,7 +84,7 @@ the following command:
:::vim
:echo 2 * 2.0

Vim displays "4.0".
Vim displays `4.0`.

Division
--------
Expand All @@ -94,14 +94,14 @@ When dividing two Numbers, the remainder is dropped. Run the following command:
:::vim
:echo 3 / 2

Vim displays "1". If you want Vim to perform floating point division one of the
Vim displays `1`. If you want Vim to perform floating point division one of the
numbers needs to be a Float, which will cause the other one to be coerced to
a Float as well. Run this command:

:::vim
:echo 3 / 2.0

Vim displays "1.5". The "3" is coerced to a Float, and then normal floating
Vim displays `1.5`. The `3` is coerced to a Float, and then normal floating
point division is performed.

Exercises
Expand Down

0 comments on commit b971c43

Please sign in to comment.