Commits

Steve Losh committed d7a6408

Moar.

Comments (0)

Files changed (4)

sample/chapters/00.markdown

 
 To use this book you should have the latest version of Vim installed, which is
 version 7.3 at the time of this writing.  New versions of Vim are almost always
-backwards-compatible, so everything in this book should work just fine with newer
-versions.
+backwards-compatible, so everything in this book should work just fine with
+newer versions.
 
 You should be comfortable editing files in Vim.  You should know basic Vim
-terminology like "buffer", "window", "normal mode", "insert mode" and "text object".
+terminology like "buffer", "window", "normal mode", "insert mode" and "text
+object".
 
-You should have some programming experience.  If you've never programmed before check
-out [Learn Python the Hard Way](http://learnpythonthehardway.org/) first.
+If you're not at that point yet go through the `vimtutor` program, use Vim
+exclusively for a month or two, and come back when you've got Vim burned into
+your fingers.
+
+You should have some programming experience.  If you've never programmed before
+check out [Learn Python the Hard Way](http://learnpythonthehardway.org/) first.
 
 Creating a Vimrc File
 ---------------------
 
-If you already know what a vimrc file is and have one, go on to the next chapter.
+If you already know what a vimrc file is and have one, go on to the next
+chapter.
 
 A vimrc file is a file you create that contains some Vimscript code.  Vim will
 automatically run the code inside this file every time you open Vim.
 
-On Linux and Mac OS X this file is located in your home directory and named `.vimrc`.
+On Linux and Mac OS X this file is located in your home directory and named
+`.vimrc`.
 
 On Windows this file is located in your home folder and named `_vimrc`.
 
 To easily find the location and name of the file on *any* operating system, run
-`:echo $MYVIMRC` in Vim.  The path will be displayed at the bottom of the screen.
+`:echo $MYVIMRC` in Vim.  The path will be displayed at the bottom of the
+screen.
 
 Create this file if it doesn't already exist.

sample/chapters/01.markdown

 
 The first piece of Vimscript we'll look at is `echom`.
 
-You can read the full documentation for the command by running `:help echom` in Vim.
-As you go through this book you should try to read the `:help` for every new command
-you encounter to get a better understanding of how to use each one.
+You can read the full documentation for the command by running `:help echom` in
+Vim.  As you go through this book you should try to read the `:help` for every
+new command you encounter to get a better understanding of how to use each one.
 
 Run the following command:
 
 
     :messages
 
-You should see a list of messages.  `Hello, world!` will *not* be in this list, but
-`Hello again, world!` *will* be in it.
+You should see a list of messages.  `Hello, world!` will *not* be in this list,
+but `Hello again, world!` *will* be in it.
 
 When you're writing more complicated Vim scripts later in this book you may find
 yourself wanting to "print some output" to help you debug problems.  Plain old
 `:echo`will print output, but it will often disappear by the time your script is
-done.  Using `:echom` will save the output and let you run `:messages` to view it
-later.
+done.  Using `:echom` will save the output and let you run `:messages` to view
+it later.
+
+Before we move on we should mention comments.  When you write Vimscript code (in
+your `~/.vimrc` file or another one) you can add comments with the `"`
+character, like this:
+
+    " Make space more useful
+    nnoremap <space> za
+
+This doesn't *always* work (that's one of those ugly corners of Vimscript), but
+in most cases it does, and we'll talk about when it won't (and why that
+happens).
 
 Exercises
 ---------

sample/chapters/02.markdown

 
     :set nonumber
 
-The line numbers should disappear.  `number` is a boolean option -- it can be off or
-on.  You turn it "on" by running `:set number` and "off" with `:set nonumber`.
+The line numbers should disappear.  `number` is a boolean option -- it can be
+off or on.  You turn it "on" by running `:set number` and "off" with `:set
+nonumber`.
 
 You can also "toggle" boolean options to set them to the *opposite* of whatever
 they are now.  Run this:
     :set numberwidth=4
     :set numberwidth?
 
-The `numberwidth` option changes how wide the column containing line numbers will be.
+The `numberwidth` option changes how wide the column containing line numbers
+will be.
+
+Try checking what a few other common options are set to:
+
+    :set wrap?
+    :set numberwidth?
 
 Finally, you can specify more than one option in the same `:set` command.  Try
 running this:

sample/chapters/03.markdown

 Basic Mapping
 =============
 
-What Should Happen
+If there's one feature of Vimscript that will let you bend Vim to your will it's
+the ability to map keys.  Mapping keys lets you tell Vim: "when I press this
+key, I want you to do this stuff instead of whatever you would normally do".
+
+We're going to start off by mapping keys in normal mode.  We'll talk about how
+to map keys in insert and other modes in the next chapter.
+
+Type a few lines of text into a file, then run:
+
+    :map \ x
+
+Put your cursor somewhere in the text and press `\`.  Notice how Vim deleted the
+character under the cursor, just like if you had pressed `x`.
+
+We already have a key for "delete that character under the cursor", so let's
+change that mapping to something slightly more useful.  Run this command:
+
+    :map \ dd
+
+Now put your cursor on a line somewhere and press `\` again.  This time Vim
+deletes the entire line, because that's what `dd` does.
+
+Special Characters
 ------------------
 
-Extra Credit
-------------
+You can use `<keyname>` to tell Vim about special keys that are hard to type.
+Try running this command:
 
+    :map <space> viw
 
+Put your cursor on a word in your text and press the space bar.  Vim will
+visually select the word.
+
+You can also map modifier keys like Ctrl and Alt.  Run this:
+
+    :map <c-d> dd
+
+Now pressing `Ctrl+d` on your keyboard will run `dd`.
+
+Commenting
+----------
+
+Remember in the first lesson where we talked about comments?  Mapping keys is
+one of the places where Vim comments don't work.  Try running this command:
+
+    :map <space> viw " Use space to select a word
+
+If you try pressing `<space>` now, something horrible will almost certainly
+happen.  Why?
+
+When you press the space bar now, Vim thinks you want it to do what
+`viw<space>"<space>Use<space>space<space>to<space>select<space>a<space>word`
+would do.  Obviously, this isn't what we want.
+
+This mapping is even more interesting though, because if you look closely at its
+effect you might notice something strange.  Take a few minutes to try to figure
+out what it is before you move on.  Don't worry if you don't get it now, because
+we'll talk about it more later.
+
+Exercises
+---------
+
+Map the `-` key to "delete the current line, then paste it below the one we're
+on now".  This will let you move lines downward in your file with one keystroke.
+
+Add that mapping command to your `~/.vimrc` file so you can use it any time
+you start Vim.
+
+Figure out how to map the `_` key to move the line up instead of down.
+
+Add that mapping to your `~/.vimrc` file too.
+
+Try to guess how you might remove a mapping and reset a key to its normal
+function.