Scripting the Vim editor, Part 3: Built-in lists
Feb 02, 2010, 23:33 (0 Talkback[s])
(Other stories by Damian Conway)
"The heart of all programming is the creation and manipulation
of data structures. So far in this series, we’ve considered
only Vimscript’s scalar data types (strings, numbers, and
booleans) and the scalar variables that store them. But the true
power of programming Vim becomes apparent when its scripts can
operate on entire collections of related data at once: reformatting
lists of text lines, accessing multidimensional tables of
configuration data, filtering sequences of filenames, and sorting
sets of line numbers.
"In this article, we’ll explore Vimscript’s
excellent support for lists and the arrays that store them, as well
as the language's many built-in functions that make using lists so
easy, efficient, and maintainable.
"Lists in Vimscript
"In Vimscript, a list is a sequence of scalar values: strings,
numbers, references, or any mixture thereof. Vimscript lists are
arguably misnamed. In most languages, a "list" is a value (rather
than a container), an immutable ordered sequence of simpler values.
In contrast, lists in Vimscript are mutable and in many ways far
more like (references to) anonymous-array data structures. A
Vimscript variable that is storing a list is, for most purposes, an
array."
Complete Story
Related Stories:
- Shell Scripts and Here Documents(Jan 26, 2010)
- Vim Tip: using "paste" to avoid the staircase effect(Dec 27, 2009)
- Vim 201: An Intermediate Guide to Vim(Nov 27, 2009)
- Vim 101: A Beginner's Guide to Vim(Nov 21, 2009)
- Matching Newlines in Vim(Oct 14, 2009)
- [e|c]tags With Emacs and Vim(Aug 18, 2009)
- Tech Tip: Some Useful Vim Options(Jul 28, 2009)
- Scripting the Vim editor, Part 2: User-defined functions(Jul 10, 2009)
- Turning on Unicode Support in Vim(Jun 23, 2009)
- Unicode Characters in Vim(Jun 17, 2009)