Indentation not working properly with the new built-in pipe "|>"
While using the magrittr pipe ("%>") automatically produces an extra space in the next line, this is not the case with the new built-in pipe. Would it possible to have the automatic indentation as well for "|>"?
Thank you very much.
I can replicate the issue, but only if in lines 1 or 2. From the third line onwards, with R-Vim-runtime up to date, a new line produces the number of white spaces defined by the 'shiftwidth' option.
Came here to report the same issue. If I may tag along, there is another issue associated with this one. Here is a reproducible example. Currently:
test <- cars |>
dplyr::mutate(speedx2 = speed * 2) |> # manually indented with a tab
dplyr::mutate(distancex2 = distance * 2) |> # manually indented with a tab
dplyr::mutate(speedxdistance = speed * distance) # automatically indented
## some comment, automatically indented
## some more comment, manually removed indentation
## some more comment, auto indentation persists
head(cars) ## manually removed indentation
## some comment, automatic indentation stopped
By default, the indentation would persist until the next line of code without indentation. Ideally, I would like the indentation to stop after a new line without indentation, be it code or comment. Not sure if this is a bug or a feature request...
This is what I'd expect:
test <- cars |>
dplyr::mutate(speedx2 = speed * 2) |>
dplyr::mutate(distancex2 = distance * 2) |>
dplyr::mutate(speedxdistance = speed * distance)
## some comment, manually remove indentation if necessary
## some more comment, auto indentation stops
@chunyunma, I didn't find additional issues with your sample code. The code seems to be correctly indented. Are you using R-Vim-runtime?
Note that Vim only understands manual indentation if it is a multiple of 'shiftwidth'...
@jalvesaq Thank you so much for following up on this. Just to clarify, when you said you "didn't find additional issues", do you mean that when you tried to type the following example, (n)vim did not automatically indent for you when you reached line 7?
1 test <- cars |>
2 dplyr::mutate(speedx2 = speed * 2) |>
3 dplyr::mutate(distancex2 = distance * 2) |>
4 dplyr::mutate(speedxdistance = speed * distance)
5
6 ## some comment, manually remove indentation if necessary
7 ## some more comment
I did not install R-vim-runtime because in the README file it says "if you have a fairly up to date Vim or Neovim, you do not need to install the files from this repository." Or do you suggest that I install it?
Indeed, I have put the expression "fairly up to date Vim or Neovim" in the documentation... But I avoid sending the updated version of runtime files to Bram Moolenaar after each small change, and I didn't send the last indent/r.vim to him yet. When I send updated runtime files, Bram takes from a few days to a few weeks to commit the changes in the Github repository and, then, Neovim's team also takes from a few days to a few weeks to import the changes. So, yes, you have to install R-Vim-runtime to benefit immediately from the new built-in pipe indentation.
I tested R-vim-runtime with minimal config and nvim --clean -u test_config.vim. However the indentation would still persist as described in my previous example.
indent/r.vim (from R-Vim-runtime) now removes comments from lines before checking if they end with an operator.