Skip to content

Commit

Permalink
Proof 01-08.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjl committed Apr 4, 2013
1 parent c3e14b4 commit e1f0293
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 81 deletions.
1 change: 1 addition & 0 deletions acknowledgements.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ pointed out typos, raised issues, and otherwise contributed:
* [manojkumarm](https://github.com/manojkumarm)
* [dmedvinsky](https://github.com/dmedvinsky)
* [flatcap](https://github.com/flatcap)

14 changes: 7 additions & 7 deletions chapters/01.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Try out `echo` by running the following command:
:::vim
:echo "Hello, world!"

You should see "Hello, world!" appear at the bottom of the window.
You should see `Hello, world!` appear at the bottom of the window.

Persistent Echoing
------------------
Expand All @@ -22,15 +22,15 @@ Now try out `echom` by running the following command.
:::vim
:echom "Hello again, world!"

You should see "Hello again, world!" appear at the bottom of the window.
You should see `Hello again, world!` appear at the bottom of the window.

To see the difference between these two commands, run the following:

:::vim
: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 Vimscript later in this book you may find
yourself wanting to "print some output" to help you debug problems. Plain old
Expand All @@ -41,9 +41,9 @@ view it later.
Comments
--------

Before moving, let's look at how to add comments. When you write Vimscript code
(in your `~/.vimrc` file or any other one) you can add comments with the `"`
character, like this:
Before moving on, let's look at how to add comments. When you write Vimscript
code (in your `~/.vimrc` file or any other one) you can add comments with the
`"` character, like this:

:::vim
" Make space more useful
Expand Down
4 changes: 2 additions & 2 deletions chapters/02.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ commands and watch what happens after each:
:set nonumber
:set number?

Notice how the first `:set number?` command displayed "number" while the second
displayed "nonumber".
Notice how the first `:set number?` command displayed `number` while the second
displayed `nonumber`.

Options with Values
-------------------
Expand Down
4 changes: 2 additions & 2 deletions chapters/03.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ one of the places where Vim comments don't work. Try running this command:
:::vim
:map <space> viw " Select word

If you try pressing `<space>` now, something horrible will almost certainly
happen. Why?
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>Select<space>word` would do. Obviously this isn't what we
Expand Down
13 changes: 7 additions & 6 deletions chapters/04.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ The `<esc>` is our way of telling Vim to press the Escape key, which will take
us out of insert mode.

Now try the mapping. It works, but notice how you're now back in normal mode.
This makes sense, because we told Vim that `<c-d>` should exit insert mode and
This makes sense because we told Vim that `<c-d>` should exit insert mode and
delete a line, but we never told it to go back into insert mode.

Run one more command to fix the mapping once and for all:
Expand All @@ -93,14 +93,15 @@ Exercises
Set up a mapping so that you can press `<c-u>` to convert the current word to
uppercase when you're in insert mode. Remember that `U` in visual mode will
uppercase the selection. I find this mapping extremely useful when I'm writing
out the name of a long constant -- I type out the constant in lower case and
then uppercase it.
out the name of a long constant like `MAX_CONNECTIONS_ALLOWED`. I type out the
constant in lower case and then uppercase it with the mapping instead of holding
shift the entire time.

Add that mapping to your `~/.vimrc` file.

Set up a mapping so that you can uppercase the current word with `<c-u>` when in
*normal* mode. This will be slightly different than the previous mapping
because you don't need to enter normal mode and you should end up back in normal
mode instead of in insert mode.
because you don't need to enter normal mode. You should end up back in normal
mode at the end instead of in insert mode as well.

Add that mapping to your `~/.vimrc` file as well.
Add that mapping to your `~/.vimrc` file.
6 changes: 3 additions & 3 deletions chapters/05.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ One downside of the `*map` commands is the danger of recursing. Another is that
their behavior can change if you install a plugin that maps keys they depend on.

When you install a new Vim plugin there's a good chance that you won't use and
memorize every mapping it uses. Even if you do, you'd have to go back and look
through your `~/.vimrc` file to make sure none of your custom mappings use a key
that the plugin has mapped.
memorize every mapping it creates. Even if you do, you'd have to go back and
look through your `~/.vimrc` file to make sure none of your custom mappings use
a key that the plugin has mapped.

This would make installing plugins tedious and error-prone. There must be
a better way.
Expand Down
18 changes: 9 additions & 9 deletions chapters/06.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ already has mechanisms for this "prefix" key!
Leader
------

Vim calls this "prefix" key "leader". You can set your leader key to whatever
you like. Run this command:
Vim calls this "prefix" key the "leader". You can set your leader key to
whatever you like. Run this command:

:::vim
:let mapleader = "-"
Expand All @@ -65,17 +65,17 @@ First of all, you may decide you need the normal function of your leader later
on down the road. Defining it in one place makes it easy to change later.

Second, when someone else is looking at your `~/.vimrc` file they'll immediately
know what you mean when you say `<leader>`, and they can simply copy your
mapping into their own `~/.vimrc` if they like it even if they use a different
leader.
know what you mean when you say `<leader>`. They can simply copy your mapping
into their own `~/.vimrc` if they like it even if they use a different leader.

Finally, many Vim plugins create mappings that start with `<leader>`. If you've
already got it set up they'll work properly and will feel familiar.
already got it set up they'll work properly and will feel familiar right out of
the box.

Local Leader
------------

Vim has a second "leader" key called "localleader". This is meant to be
Vim has a second "leader" key called "local leader". This is meant to be
a prefix for mappings that only take effect for certain types of files, like
Python files or HTML files.

Expand All @@ -86,10 +86,10 @@ book, but you can go ahead and set your "localleader" now:
:let maplocalleader = "\\"

Notice that we have to use `\\` and not just `\` because `\` is the escape
character in strings. You'll learn more about this later.
character in Vimscript strings. You'll learn more about this later.

Now you can use `<localleader>` in mappings and it will work just like
`<leader>` does, except for resolving to a different key.
`<leader>` does (except for resolving to a different key, of course).

Feel free to change this key to something else if you don't like backslash.

Expand Down
61 changes: 12 additions & 49 deletions chapters/07.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ Editing Your Vimrc
Before we move on to learning more Vimscript, let's find a way to make it easier
to add new mappings to our `~/.vimrc` file.

When you're coding away furiously at a problem and realize a new mapping would
make your life easier, you should add it to your `~/.vimrc` file right then and
there to make sure you don't forget, but you *don't* want to lose your
Sometimes you're coding away furiously at a problem and realize a new mapping
would make your editing easier. You should add it to your `~/.vimrc` file right
then and there to make sure you don't forget, but you *don't* want to lose your
concentration.

The idea is that you want to make it easier to make it easier to edit text.
The idea of this chapter is that you want to make it easier to make it easier to
edit text.

That's not a typo. Read it again.

The idea is that you want to (make it easier to (make it easier to (edit
text))).
The idea of this chapter is that you want to (make it easier to (make it easier
to (edit text))).

Editing Mapping
---------------
Expand All @@ -28,7 +29,7 @@ quickly edit it and get back to coding. Run this command:
I like to think of this command as "**e**dit my **v**imrc file".

`$MYVIMRC` is a special Vim variable that points to your `~/.vimrc` file. Don't
worry about that for right now, just trust me that that variable works.
worry about that for right now, just trust me that it works.

`:vsplit` opens a new vertical split. If you'd prefer a horizontal split you
can replace it with `:split`.
Expand All @@ -44,45 +45,6 @@ take less than half a second to type.
When you're in the middle of coding and come up with a new mapping that would
save you time it's now trivial to add it to your `~/.vimrc` file.

Meta Efficiency
---------------

This is important because part of becoming more efficient is making it *easier*
for yourself to become more efficient!

Think of it this way: suppose you're trying to become a better digital
photographer. When you're practicing taking photos and want to see how they
came out, you:

* Take a photo.
* Upload it to your computer.
* Open it and see how it looks.

That process probably takes a minute. What if you could improve that?

Let's say you invest $50 and buy an [Eye-Fi](http://www.eye.fi/). The Eye-Fi is
a memory card for your camera that has a built-in wifi card, so as soon as you
snap a photo it gets transferred to your computer.

I know, we're definitely living in the future. Isn't it awesome?

Now you spend an hour and write a little script to automatically open the photos
that get transferred to your computer by the Eye-Fi.

You've spent $50 and one hour, but now instead of taking a full minute to check
your work, it takes ten seconds.

Assuming you charge $100 per hour for freelance work, you've got to make up one
and a half hours of time for this investment to be worthwhile. If you're saving
50 seconds per photo, you need to take about 109 photos for project to pay for
itself.

109 photos is *nothing*. You'd blow past that number in a day's practice
without even noticing!

The same goes for our new mapping. It saves us only a few seconds each time we
use it, but it pays for itself if we use it often enough.

Sourcing Mapping
----------------

Expand All @@ -105,12 +67,12 @@ Now you can easily add new mappings during the heat of coding:

* Use `<leader>ev` to open the file.
* Add the mapping.
* Use `ZZ` to write the file and close the split, bringing us back to where we
were.
* Use `:wq<cr>` (or `ZZ`) to write the file and close the split, bringing you
back to where you were.
* Use `<leader>sv` to source the file and make our changes take effect.

That's eight keystrokes plus whatever it takes to define the mapping. It's very
little overhead, which reduces the chance that we break our concentration.
little overhead, which reduces the chance of breaking focus.

Exercises
---------
Expand All @@ -121,3 +83,4 @@ Add mappings to "edit my `~/.vimrc`" and "source my `~/.vimrc`" to your
Try them out a few times, adding dummy mappings each time.

Read `:help myvimrc`.

6 changes: 3 additions & 3 deletions chapters/08.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Now enter insert mode and type:
:::text
One adn two.

As soon as you hit space after typing the "adn" Vim will replace it with "and".
As soon as you hit space after typing the `adn` Vim will replace it with `and`.

Correcting typos like this is a great use for abbreviations. Run these
commands:
Expand Down Expand Up @@ -57,7 +57,7 @@ considered "keyword characters":

If you want to read the *full* description of this option's format you can check
out `:help isfname`, but I'll warn you that you'd better have a beer at the
ready if you don't want to start crying while reading.
ready for this one.

For our purposes you can simply remember that abbreviations will be expanded
when you type anything that's not a letter, number, or underscore.
Expand All @@ -70,7 +70,7 @@ more that can help in day-to-day text editing. Run the following commands:

:::vim
:iabbrev @@ steve@stevelosh.com
:iabbrev ccopy Copyright 2011 Steve Losh, all rights reserved.
:iabbrev ccopy Copyright 2013 Steve Losh, all rights reserved.

Feel free to replace my name and email address with your own, then enter insert
mode and try them out.
Expand Down
11 changes: 11 additions & 0 deletions style.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Output should be enclosed in backticks. So:

If you type `:echom "Hello!"` Vim will output `Hello`.

Key mappings should be lowercase.

nnoremap <esc> ...

Keep code within 70 or so cols.

Prefix code blocks with :::vim or :::text.

0 comments on commit e1f0293

Please sign in to comment.