ARCHIVED: Using the vi editor, how can I automatically indent lines?

This content has been archived, and is no longer maintained by Indiana University. Information here may no longer be accurate, and links may no longer be available or reliable.

To automatically indent lines using the vi editor, set the autoindent flag:

  1. If you are currently in insert or append mode, press Esc.
  2. Press : (the colon). The cursor should reappear at the lower left corner of the screen beside a colon prompt.
  3. Enter the following command:
      set autoindent

Now, when you are inserting text, if you press Enter at the end of your text, vi will automatically indent the next new line to match the indent of the previous one. This is useful for editing tables with indented columns or program source code.

To turn off the automatic indentation, follow the preceding instructions; however, in step 3, at the colon prompt, enter:

  set noautoindent

Normally vi will "forget" the particular setting you've chosen once you've left the editor. You can make either setting take effect automatically whenever you use vi on a particular account by placing the appropriate set statement as a line in a file in your home directory named .exrc.

For a list of all current settings, at the colon prompt, enter:

  set all

At Indiana University, for personal or departmental Linux or Unix systems support, see Get help for Linux or Unix at IU.

Related documents

This is document afcw in the Knowledge Base.
Last modified on 2018-01-18 10:18:27.