Question: Vim autoindents too far (more than 4 spaces) for the following R code:

```
lapply(1:10, function(x){
       Something here
})

```

How can I fix this? 

Here is a picture:

[![Vim autoindents too far with an lapply](https://i.stack.imgur.com/Ilm8A.png)](https://i.stack.imgur.com/Ilm8A.png)

Here is a minimal .vimrc which replicates this behaviour when editing files with a .R extension:

```
filetype on
filetype plugin on
filetype indent on
set ts=4 sw=4 

```

Answer: 
I've found the solution:

Adding

```
let r_indent_align_args = 0

```

to my .vimrc fixed the problem. See :h ft-r-indent for further information.
Just use .vimrc option shiftwidth (for 2 spaces):

`set shiftwidth=2`

Source:
<http://vimdoc.sourceforge.net/htmldoc/options.html#'shiftwidth'>