Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: autoindent not working

Tags:

my autoindent is not working, any diagnostic tests to figure it out?

my ":set" is:

:set --- Options --- cindent laststatus=2 scroll=17
tabstop=4 window=36
filetype=cpp number
smartindent ttyfast
helplang=en paste
syntax=cpp ttymouse=xterm2
backspace=indent,eol,start
fileencoding=utf-8
fileencodings=ucs-bom,utf-8,default,latin1 printoptions=paper:letter
runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim72,/usr/share/vim/vimfiles/af ter,/var/lib/vim/addons/after,~/.vim/after suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc

like image 579
l7ecl Avatar asked Oct 15 '10 00:10

l7ecl


People also ask

How do I enable Autoindent in Vim?

How to Turn On Auto Indent in Vim. To automatically indent when editing a file in Vim, enable the auto indenting feature using the :set autoindent flag in command mode: Press Enter, and this will auto-indent the file you are currently editing.

How do I turn off Autoindent in Vim?

To turn off autoindent when you paste code, there's a special "paste" mode. Then paste your code. Note that the text in the tooltip now says -- INSERT (paste) -- . After you pasted your code, turn off the paste-mode, so that auto-indenting when you type works correctly again.

How do I indent a whole file in Vim?

Start in the top of a file (to get there, press gg anywhere in the file.). Then press =G , and Vim will fix the indentation in the whole file. If you don't start in the beginning of the file, it will fix indentation from current line to the bottom of file.

How do you set a tab to 4 spaces in vim?

Tab key == 4 spaces and auto-indent after curly braces in Vim.


2 Answers

try:

:set ai

or:

:set autoindent

find more about auto-indent:

:h ai

Otherwise, it's might be something with file type detection.

like image 187
Andrew_1510 Avatar answered Oct 02 '22 18:10

Andrew_1510


I had a stale function in indentexpr which persisted after changing the filetype. This eventually fixed it for me:

:set indentexpr=
like image 25
hraban Avatar answered Oct 02 '22 17:10

hraban