Using the vi editor, how can I automatically indent lines?
To automatically indent lines using the vi editor, set the autoindent flag:
- If you are currently in insert or append mode, press
Esc.
- Press
:(the colon). The cursor should reappear at the lower left corner of the screen beside a colon prompt.
- 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 noautoindentNormally 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 allAt Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?
Last modified on May 13, 2009.







