Kim Schulz wrote:
On Thu, 24 Aug 2006 10:46:26 +0200, "A.J.Mechelynck" <[EMAIL PROTECTED]> wrote:
Kim Schulz wrote:
Hi is there a way to make indentation in Vim "lock" like in emacs so
that if I press tab in the beginning of a line, then it indents the line
to the correct place. Pressing tab multiple times does not change the
indentation any further - it is locked.
'autoindent' will indent the line to the same location as the line the
cursor was on before hitting Enter in Insert mode, o or O in Normal
mode, etc.
I suppose that you could force a fixed indent of, say, 6 characters
(i.e., always indent to column 7) by using
:setlocal indentexpr=6
To use it in all buffers, use
:filetype indent off
:set indentexpr=6
What I need is for it to be context sensitive. so if I have
if (foo == bar) {
// one fixed indent
if (bar == baz) {
//another fixed indent
}
}
That is filetype-dependent indent, since how to indent will be
determined by the syntax of the language of the file being edited:
:filetype indent on
or (usually better)
:filetype plugin indent on
If you source the vimrc_example.vim by means of
:runtime vimrc_example.vim
or
:source $VIMRUNTIME/vimrc_example.vim
, it includes ":filetype plugin indent on".
The width of the relative indent is usually defined by the 'shiftwidth'
option. By default, 'shiftwidth' (the width of an indent) and 'tabstop'
(the width of a hard tab) both default to 8, and 'softtabstop' (by how
much the cursor moves when you hit <Tab>) defaults to zero (meaning use
the value of 'tabstop'). In general, I don't recommend setting 'tabstop'
to anything other than 8, for compatibility reasons with some other
editors and compilers.
Best regards,
Tony