Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

autoindent is subset of smartindent in vim?

Tags:

vim

vi

:help autoindent : Copy indent from current line when starting a new line (typing in Insert mode or when using the "o" or "O" command). ...

:help smartindent : Do smart autoindenting when starting a new line. Works for C-like programs, but can also be used for other languages. ...

Normally 'autoindent' should also be on when using 'smartindent'. An indent is automatically inserted:

  • After a line ending in '{'.
  • After a line starting with a keyword from 'cinwords'.
  • Before a line starting with '}' (only with the "O" command).

    When typing '}' as the first character in a new line, that line is given the same indent as the matching '{'. ...

smartindent also coping indent from current line when starting a new line. That means autoindent feature is subset of smartindent feature and no need of autoindent if smartindent is on, right? Why autoindent should be turn on?

like image 560
Mohammed H Avatar asked Aug 24 '13 06:08

Mohammed H


People also ask

What is Autoindent in vim?

Vim has four methods of indentation, namely: Autoindent – this method uses indent from the previous line for the file type you are editing. smartindent – smartindent works similarly to autoindent but recognizes the syntax for some languages such as C language.

How do I turn off auto indent in vim?

vim" in 'runtimepath'. This disables auto-indenting for files you will open. It will keep working in already opened files. Reset 'autoindent', 'cindent', 'smartindent' and/or 'indentexpr' to disable indenting in an opened file.


1 Answers

smartindent is an old script that was meant, when it was written, to be a "smart" complement to autoindent. Since then, most languages have either specific indentation functions or use cindent with specific options.

Generally, smartindent shouldn't be used at all.

The following lines are usually enough to deal with indentation:

set autoindent filetype plugin indent on 

autoindent is not strictly necessary but it's good to have it when working with plaintext.

like image 98
romainl Avatar answered Sep 18 '22 17:09

romainl