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
:(the colon). The cursor should reappear at the lower left corner of the screen beside a colon prompt.
- Enter the following command:
Now, when you are inserting text, if you press
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:
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
For a list of all current settings, at the colon prompt, enter:
At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?
This is document afcw in the Knowledge Base.
Last modified on 2009-05-13 00:00:00.
- Fill out this form to submit your issue to the UITS Support Center.
- Please note that you must be affiliated with Indiana University to receive support.
- All fields are required.