# HG changeset patch # User Steve Losh # Date 1353115026 18000 # Node ID f3840721739b051415215e7d14824c931dfb930b # Parent cc9d7d8f821443e480355c2ccde77aec1dab1509 Proof 19-20. diff -r cc9d7d8f8214 -r f3840721739b chapters/19.markdown --- a/chapters/19.markdown Thu Nov 15 22:21:05 2012 -0500 +++ b/chapters/19.markdown Fri Nov 16 20:17:06 2012 -0500 @@ -3,13 +3,12 @@ Up to this point we've covered single commands. For the next third of the book we're going to look at Vimscript as a *programming language*. This won't be as -instantly gratifying as the rest of what we've learned, but it will lay the -groundwork for the last part, which walks through creating a full-fledged Vim -plugin from scratch. +instantly gratifying as the rest of what you've learned, but it will lay the +groundwork for the last part of the book, which walks through creating +a full-fledged Vim plugin from scratch. -The first thing we need to talk about are variables. - -Run the following commands: +Let's get started. The first thing we need to talk about are variables. Run +the following commands: :::vim :let foo = "bar" @@ -22,9 +21,10 @@ :let foo = 42 :echo foo -Vim will display "42", because we've reassigned `foo` to the integer "42". From -this it may seem that Vimscript is dynamically typed. That's not the case, but -we'll talk more about that later. +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. Options as Variables -------------------- @@ -53,8 +53,9 @@ :echo &wrap 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's reasonable to assume -that Vim treats *any* non-zero integer as "truthy", and this is indeed the case. +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. We can also *set* options as variables using the `let` command. Run the following commands: @@ -127,14 +128,14 @@ :echo @/ Vim will echo the search pattern you just used. This lets you programmatically -read and modify the current search pattern, which can be very useful at times. +read *and modify* the current search pattern, which can be very useful at times. Exercises --------- -Go through your `~/.vimrc` file and change some of the `set` and -`setlocal` commands to their `let` forms. Remember that boolean options still -need to be set to something. +Go through your `~/.vimrc` file and change some of the `set` and `setlocal` +commands to their `let` forms. Remember that boolean options still need to be +set to something. Try setting a boolean option like `wrap` to something other than zero or one. What happens when you set it to a different number? What happens if you set it diff -r cc9d7d8f8214 -r f3840721739b chapters/20.markdown --- a/chapters/20.markdown Thu Nov 15 22:21:05 2012 -0500 +++ b/chapters/20.markdown Fri Nov 16 20:17:06 2012 -0500 @@ -5,15 +5,15 @@ language like Python or Ruby. For the most part variables act like you would expect, but Vim adds a certain twist to variables: scoping. -Open two buffers in separate splits, then go into one of then and run the -following commands: +Open two different files in separate splits, then go into one of them and run +the following commands: :::vim :let b:hello = "world" :echo b:hello As expected, Vim displays "world". Now switch to the other buffer and run the -echo command again: +`echo` command again: :::vim :echo b:hello @@ -35,4 +35,3 @@ don't know what some of them mean, just take a look and keep them in the back of your mind. -