ftdetect
author |
Steve Losh <steve@stevelosh.com> |
date |
Sun, 13 Nov 2011 19:12:41 -0500 |
parents |
274674dc2025 |
children |
dc6a6332b281 |
Preface
=======
Programmers shape ideas into text.
That text gets turned into numbers and those numbers bump into other numbers
and *make things happen*.
To get our ideas out of our heads and create the chunks of text we call
"programs" we use text editors. Full-time programmers will easily spend tens of
thousands of hours of their lives interacting with their text editor doing many
things:
* Getting raw text from brains into computers.
* Correcting mistakes in that text.
* Restructuring the text to formulate a problem in a different way.
* Recording how and why something was done a particular way.
* Communicating with other programmers about all of these things.
Vim is incredibly powerful out of the box, but it doesn't truly shine until you
take some time to customize it for your particular work, habits, and fingers.
This book will introduce you to Vimscript, the main programming language used to
customize Vim. You'll be able to mold Vim around your own personal text editing
and make the rest of your time in Vim more efficient.
Along the way I'll also mention things that aren't strictly about Vimscript, but
are more about learning and being more efficient in general. Learning Vimscript
isn't going to help you much if you wind up fiddling with your editor all day
instead of working, so you have to strike a balance.
The style of this book is a bit different from most other books about
programming languages. Instead of simply presenting you with facts about how
Vimscript works, it guides you through typing in commands to see what they do.
Frequently the book will lead you into dead ends before explaining the "right
way" to solve a problem. Most other books don't do this, or only mention the
sticky issues *after* showing you the solution.
This isn't how things typically happen in the real world, though. Most of the
time you'll be whipping up a quick piece of Vimscript and run into a quirk of
the language that you'll need to figure out. By stepping through this process
in the book instead of glossing over it I hope to get you used to the process of
dealing with Vimscript's silliness so you're ready when you find other edge
cases. Practice makes perfect.
Each chapter of the book focuses on a single topic. They're short but packed
with information, so don't just skim them. If you really want to learn the most
you can you need to *type in* all of the commands.
You may already be an experienced programmer who's used to reading code and
understanding it straight away. If so: it doesn't matter. Learning Vim and
Vimscript is a different experience from learning a normal programming language.
**Type in *all* the commands.**
**Do *all* the exercises.**
There are two reasons this is so important. First, Vimscript is old and has
a lot of dusty corners and twisty hallways. One configuration option can change
how the entire language works. By typing *every* command in *every* lesson
exercise and doing *every* exercise you'll discover problems with your Vim build
or configuration on the simpler commands, which will be easier to diagnose and
fix.
Second, Vimscript *is* Vim. To save a file in Vim, you type `:write` (or `:w`
for short) and press return. To save a file in a Vimscript, you use `write`.
Many of the Vimscript commands you'll learn can be used in your day-to-day
editing as well, but they're only helpful if they're in your muscle memory,
which simply doesn't happen from just reading.
I hope you'll find this book useful. It's *not* meant to be a comprehensive
guide to Vimscript. It's meant to get you comfortable enough with the language
to write some simple plugins, read other people's code (with regular side-trips
to `:help`), and recognize some of the common pitfalls.
Good luck!