z/OS UNIX System Services User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Controlling indention

z/OS UNIX System Services User's Guide
SA23-2279-00

The source code for a program differs from ordinary text in a number of ways. One of the most important of these is the way in which source code uses indention. Indention shows the logical structure of the program: the way in which statements are grouped into blocks.

Issue the command:
:set autoindent
(Don't forget to press<Enter>after you have typed this.) This command turns on an option supplied primarily to control indention when entering source code. Each line is automatically indented the same distance as the previous one. As a programmer, you will find this saves you quite a bit of work getting the indention right, especially when you have several levels of indention.
When you are entering code with autoindent enabled, typing <EscChar-T> gives you another level of indention, and typing <EscChar-D>takes one away. While you are in Insert Mode (not Command Mode):
  • Type <EscChar-T> at the start of a line to indent it in one level.
  • Type <EscChar-D> at the start of a line to indent it out one level.
The amount of indention provided by <EscChar-T> is one tab character; the space depends on the setting of tabstop.

Try using the autoindent option when you are entering source code. It simplifies the job of getting indention correct. It can even sometimes help you avoid bugs; for example, in C source code, you usually need one closing } for every level of indention you go backwards.

The << and >> commands are also helpful when indenting source code:
>>
Shifts a line right 8 spaces (that is, adds 8 spaces of indention)
<<
Shifts a line left 8 spaces (that is, removes 8 spaces of indention)

You can shift a number of lines by typing the number followed by >> or <<. For example, typing 5>> will indent five lines, including the line the cursor is on.

The default shift is 8 spaces (right or left). You can change this default with this command:
:set shiftwidth=4

Tip: It is convenient to have a shiftwidth that is the same size as the width between tab stops.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014