Tuesday, July 24, 2012

Re: C-indentation not working?

On Tuesday, July 24, 2012 9:48:23 AM UTC-5, Axel Bender wrote:
> After starting vim (7.3.608) via
>
> gvim -U NONE -u NONE test.c
>
> and setting
>
> nocompatible cindent indentexpr=cindent autoindent smartindent filetype=c
>

:help 'indentexpr' says:

'indentexpr' 'inde' string (default "")
local to buffer
{not in Vi}
{not available when compiled without the |+cindent|
or |+eval| features}
Expression which is evaluated to obtain the proper indent for a line.
It is used when a new line is created, for the |=| operator and
in Insert mode as specified with the 'indentkeys' option.
When this option is not empty, it overrules the 'cindent' and
'smartindent' indenting.

Read that last sentence again. By setting indentexpr=cindent you are not telling Vim to use C indenting, you're telling it "evaluate the global variable named cindent to determine the indentation of the line, and ignore the 'cindent' option". If cindent is not a valid variable name (it won't be unless you set it yourself) the expression returns an error instead.

To use C indenting you would instead want:

:set nocompatible cindent indentexpr= noautoindent nosmartindent filetype=c

Or even better, before loading the file:

:filetype indent on

By the way, if you want to launch Vim in nocompatible mode without setting it explicitly, pass the -N flag:

gvim -N -u NONE -U NONE test.c

I normally also pass the -i flag if I'm testing something, to bypass reading the .viminfo file as well:

gvim -N -u NONE -U NONE -i NONE test.c

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment