Chapter 12. Vim Scripts
Sometimes customization alone isn’t enough for your editing environment. Vim lets you define all of your favorite settings in your .vimrc file, but maybe you want more dynamic or “just in time” configuration. Vim scripts let you do that.
From inspecting buffer contents to handling unanticipated external factors, Vim’s scripting language lets you complete complex tasks and make decisions based on your needs.
If you have a Vim configuration file (.vimrc, .gvimrc, or both), you are already scripting
in Vim; you just don’t know it. All of the Vim commands and options are
valid inputs to scripts. And, as you’d expect, Vim provides all of the
standard flow control (if...then...else
, while
, etc.), variables, and functions typical
in any language.
In this chapter, we’ll walk through an example and incrementally build up a script. We’ll look at simple constructs, use some of Vim’s built-in functions, and examine rules you must consider in order to write well-behaved and predictable Vim scripts.
Get Learning the vi and Vim Editors, 7th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.