Indent code on column index in Vim?

I am using Vim to edit Erlang code. I'm used to the fact that (most Erlang programmers do this) to make Erlang code indented by the area of ​​the brackets in which they are located. For example, C often has padding on the same tab width inside braces:

int main(void) { printf("hello, world\n"); return 0; } 

In Erlang, this usually refers to indentation based on a parenthesis start column:

 ?assertError({bad_options, [{foo, bar}, bad_option]}, lhttpc:request("http://localhost/", get, [], <<>>, 1000, [bad_option, {foo, bar}])). 

(The above example is indented to get a point, not subjective beauty).

Tab width will be used if the block is launched in 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 indent this in Vim, and if so, how?

+6
source share
2 answers

There is a vimerl fork that implements "context-dependent indentation" instead of "static indentation": https://github.com/aszlig/vimerl.git

It seems to work, so I'll show it off for a while.

+4
source

Sounds like you need to delve into the muddy world of cindent and cinoptions . I believe that adding the following to your vimrc will partially satisfy your needs:

 set cindent set cinoptions+=(0 

But the question is how this will affect other behavior. See help cinoptions-values for more details. This should be possible to achieve exactly what you want, but it may take some time.

Hope this helps.

+1
source

Source: https://habr.com/ru/post/896768/


All Articles