I'm using Vim to edit Erlang code. I'm used to (most Erlang programmers do this) to indent Erlang code by the bracket scope they're in. For example, C is often indented one tab width inside curly brackets:
int main(void) {
printf("hello, world\n");
return 0;
}
In Erlang, it's common to indent based on the column where the bracket started:
?assertError({bad_options, [{foo, bar},
bad_option]},
lhttpc:request("http://localhost/", get, [], <<>>, 1000,
[bad_option, {foo, bar}])).
(Example above is indented to get the point across, not according to subjective beauty).
Tab width would be used if the block is started on a new line:
?assertError(
{bad_options, [{foo, bar}, bad_option]},
lhttpc:request(
"http://localhost/", get, [], <<>>, 1000,
[bad_option, {foo, bar}]
)
).
Relevant parts of my .vimrc:
set expandtab " Spaces for tabs "
set tabstop=4 " Tab width 4 "
set shiftwidth=4
set smarttab
set autoindent
" Enable filetype plugin "
filetype plugin on
filetype indent on
Is there a way to perform this indentation in Vim, and if so, how?
There is a fork of vimerl which implements "context aware indentation" instead of "static indentation": https://github.com/aszlig/vimerl.git
Seems to work, so I'll roll with that for a while.
This looks you need delve into the murky world of cindent
and cinoptions
. I believe that putting the following in your vimrc will partially meet your needs:
set cindent
set cinoptions+=(0
But the question is how this will affect other behaviour. See help cinoptions-values
for much more information. It should possible to achieve precisely what you want, but it might take some experimenting.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With