Cover by Linda Lamb, Elbert Hannah, Arnold Robbins

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Auto and Smart Indenting

Vim offers four increasingly complex and powerful methods to automatically indent text. In its simplest form, Vim behaves almost identically to vi’s autoindent option, and indeed it uses the same name to describe the behavior.

You can choose the indentation method simply by specifying it in a :set command, such as:

:set cindent

Vim offers the following methods, listed in order of increasing sophistication:

autoindent

Auto indentation closely mimics vi’s autoindent. It differs subtly as to where the cursor is placed after indentation is deleted.

smartindent

Slightly more powerful than autoindent, but it recognizes some basic C syntax primitives for defining indentation levels.

cindent

As its name implies, cindent embodies a much richer awareness of C syntax and introduces sophisticated customization beyond simple indentation levels. For example, cindent can be configured to match your (or your boss’s) favorite coding style rules, including but not limited to how braces ({}) indent, where braces are placed, whether either or both braces are indented, and even how indentation matches included text.

indentexpr

Lets you define your own expression, which Vim evaluates in the context of each new line you begin. With this feature, you write your own rules. We refer you to the discussions of scripting and functions in this book and to the Vim documentation for details. If the other three options don’t give you enough flexibility for automatic indentation, indentexpr certainly ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required