Sunday, September 20, 2015

How to configure with auto-indent in vi / vim editor.

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
    4. Now press enter.

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. But if you want to make this setting permanent, You can make 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 "vim" directory named: ~/.vimrc

    1.Open the terminal and go to "vim" directory.. Enter the following commands bellow..
              a. cd ..
                  Now you are in home directory.
              b. cd ..
                  Now you are in root directory.
              c. cd usr
                  Now you are in user directory.
              d. cd share
                  Now you are in share directory.
              e. cd vim
                  Now you are in vin directory which contains the file ~/.vimrc
    2. Now enter the command: gedit ~/.vimrc
        Text editor will open the ~/.vimrc file
    3. Now add the following command to that file
                       :set autoindent
                       :set smartindent
                       :set cindent
    4. Now save the file and close that file.
    5. Close the terminal and reopen it again.. thats it. |Enjoy|

No comments:

Post a Comment