small medium large xlarge

The VimL Primer; Mastering Ruby Blocks & Iterators online course

January 14, 2015

Happy New Year to those of you on the Julian calendar, which is currently 13 days behind the Gregorian calendar. It's interesting how your perspective can change based on the tools you use. And speaking of tools…

If you use Vim, the most excellent vi-style editor, then you need The VimL Primer, now in print and shipping from pragprog.com/book/bkviml. If you don't use Vim, then consider starting! (pragprog.com/book/dnvim and pragprog.com/book/bhtmux are great places to start).

Want to jump start your Ruby programming? Try the new online course, Mastering Ruby Blocks & Iterators (pragmaticstudio.com/ruby-blocks) from our friends at the Pragmatic Studio.

Read on for details…

The VimL Primer: Edit Like a Pro with Vim Plugins and Scripts

VimL is the scripting language of the Vim editor. If you've ever edited or saved a vimrc file, you've written VimL. And VimL can do much more than simply configure settings and specify option values—you can write entire plugins in VimL. But without a background in scripting Vim, it can be hard to know where to start.

The VimL Primer gives you the tools and confidence you need. It gets you comfortable in VimL quickly, walking you through creating a working plugin that you can run yourself as you write it in Vim. You'll learn how to script common commands and buffer interaction, work with windows and buffers from within a plugin script, and how to use autocommands to have Vim recognize entirely new filetypes. You'll discover how to declare filetype-specific settings and define your own syntax elements for use with Vim's syntax highlighting. And you'll see how you can write your own command-line commands and define new mappings to call them.

With this introduction to scripting Vim, your own Vim extensions are only plugins away. Take control of your editor!

Now available from pragprog.com/book/bkviml.

Q&A with author Ben Klein:

1. I don’t want to write plugins. Why should I care about VimL?

Not so fast, there! In fact, you’re executing lines of VimL each time you run a command on Vim’s command line (as we discuss in Chapter 1). If you have a Vim configuration file – .vimrc – you have a VimL script that Vim is reading every time it launches.

You don’t have to write a plugin as such to benefit from VimL. (And once you’re comfortable with scripting, you might eventually come to separate scripts into a plugin for your own use, but if you do, you don’t necessarily have to distribute it.) The concepts and techniques you’ll learn in this book will aid you in customizing or extending Vim, all plugins aside.

2. There’s no such thing as VimL! What is this book about?

This book is about Vim’s built-in scripting language, VimL. This language is also known as Vimscript. Depending on how you look at it, either VimL is an alternate name for Vimscript or Vimscript is an alternate name for VimL.

Actually, there’s no real official name for the language; the closest seems to be the two-word “Vim script.” To better follow English naming conventions, this is usually altered to “Vimscript,” or more rarely, “Vim Script”—but all of this can be confusing, since the files which store code in this language are themselves called “Vim scripts.”

The relatively new name “VimL” (“Vim Language”) has been gaining in popularity in rough correlation with the growth of the code-sharing site GitHub. Its use is a matter of preference, but I do find it more easily distinguishable from mentions of Vim scripts or of writing generic scripts using Vim (in search results, for instance). It’s a short, tolerably memorable name, a bit catchy, and what I use throughout this book.

3. Does this book cover Vim scripting in Python or Ruby?

No.

That’s the short answer. The long answer is that Vim does let you script it in common languages such as Python, but also that when you do this, you still have to work with a VimL interface (in the Python example, at the very least you’ll need some VimL that loads the Python code). It can only help to have some VimL background before you attempt to do this.

This book is an introduction to scripting Vim. For that, the official (default) language is VimL, and that’s what this book introduces.

So: No.

4. Can I get the plugin from the book somewhere?

Absolutely! You can get the current version of the plugin from GitHub. That project starts with the code from the book (beginning with how we leave the plugin at the end of Chapter 6) and will build on it. Feel free to fork it, send pull requests, create issues, or do any number of the other cool things GitHub lets you do with it there.

If you have any comments, questions, suggestions, criticisms, or debts of unending gratitude regarding the plugin code or the book, you can let me know on Twitter: @fifthposition

Now available from pragprog.com/book/bkviml.

New Course: Mastering Ruby Blocks & Iterators

Experienced Ruby (and Rails) developers repeatedly turn to certain programming techniques to improve the design of their code. One such technique is the effective use of Ruby blocks. Blocks are a powerful aspect of the language and they're used pervasively throughout Ruby's standard library. It's no surprise then that to use Ruby well requires proficiency with blocks.

But programming with blocks goes far beyond simply calling methods that take blocks, which is where most amateurs stop. The real pros move to higher ground: using blocks to inform the design of their own code and libraries, the Ruby way! In turn, block-savvy developers consistently design Ruby code that's more expressive, elegant, and fun to work with.

The latest online course from The Pragmatic Studio is your path to Ruby blocks mastery. You'll learn not just how blocks work, but more importantly, you'll understand when and where to use them to super-charge your own code. Their new Mastering Ruby Blocks and Iterators course (pragmaticstudio.com/ruby-blocks) is jam-packed with:

  • real-world examples demonstrating blocks in action
  • animations to deepen your understanding of block concepts
  • refactoring and design techniques using blocks
  • use cases for blocks and iterators in a variety of practical scenarios

Take this online, self-paced course and you'll become a master of Ruby blocks! Use coupon code "BLOCKSROCK" and save 25% on this course, or 10% on any of Pragmatic Studio's other courses. (Coupon expires end of day Wednesday, January 21, 2015.)

"Since finishing the class I'm writing methods with fresh eyes!" – Dan Wagner

"I'd read about Ruby blocks before, but nothing really clicked until I worked through this course." – Tom Belunis

"I suddenly feel newly empowered!" – Thom Parkin

Now available at pragmaticstudio.com/ruby-blocks.

Upcoming Author Appearances

  • 2015-01-15 Johanna Rothman, Why Project Management is Broken and 3 Ways to Fix It
  • 2015-01-27 Johanna Rothman, Geographically Distributed Agile Teams Webinar
  • 2015-01-27 James Grenning, OOP Conference, Munich, Germany
  • 2015-01-28 Rachel Davies, OOP conference, Munich, Germany
  • 2015-01-28 James Grenning, OOP Conference, Munich Germany
  • 2015-01-29 Andrew Hunt, Leadership In Technology Series
  • Did You Know?

    You can synch your ebooks amongst your devices via Dropbox, including updates! Just login to your account on pragprog.com, edit your profile, and connect your dropbox account. See our FAQ for details.

    Don't Get Left Out

    Are your friends jealous that you get these spiffy email newsletters and they don't? Clue them in that all they need to do is create an account on pragprog.com (email address and password is all it takes) and select the checkbox to receive newsletters.

    Are you following us on Twitter and/or Facebook? Here's where you can find us and keep up with the latest news and commentary, and occasional discounts:

    Tell your friends! Tweet this

    Follow us on Twitter: @pragprog, @pragpub, Andy @PragmaticAndy and Dave @pragdave.

    Coming Soon:

    • Arduino: A Quick Start Guide, Second Edition, in print
    • Hello, Android, Fourth Edition
    • Metaprogramming Elixir

    Recently Released:

    Thanks for your continued support,

    Dave & Andy The Pragmatic Programmers

    Books • eBooks • PragPub Magazine • Audiobooks and Screencasts
    PragProg.com