Closed wurli closed 3 months ago
The indentation is defined in the official Vim runtime file indent/r.vim
, not by R.nvim
or Nvim-R
. I used to be the maintainer of the Vim runtime files for R, but no longer. See: https://github.com/vim/vim/blob/master/runtime/indent/r.vim
I'm no longer the maintainer of the Vim runtime files for R because I only use Neovim which (with tree-sitter) doesn't use the syntax and indent scripts from Vim. The ftplugin scripts are still used, but lately, I was wasting my time adding features that Lua plugins don't require to work. For example, in this commit, I turned the value 'commentstr' dynamic, but Comment.nvim uses tree-sitter instead of 'commentstr' to define the comment string. So, I implemented a feature that would be useful only for Vim, not Neovim while I no longer use Vim to see if the feature works well or has bugs.
Please, see also: https://github.com/jalvesaq/Nvim-R/issues/577#issuecomment-1892587154
Thank you, your explanation is much appreciated.
So if I understand correctly, the vim.g.r_indent_align_args
setting comes from the vim runtime file indent/r.vim
, but Neovim uses treesitter for indentation. Does treesitter then make use of this parameter? I'm a bit confused as to why setting vim.g.r_indent_align_args = 0
worked if Neovim doesn't use the indentation scripts from Vim.
Neovim still uses the syntax and indent files by default, but Neovim's team is investing in a tree-sitter-based solution as a replacement. Currently, you have to install nvim-treesitter and explicitly enable highlighting and indenting via treesitter
. I already have syntax highlighting via treesitter
enabled, but not indenting yet. Anyway, the indent/r.vim
script was the one I disliked most because it's too big, slow, and still has bugs. I decided to abandon the whole R-Vim-runtime repository and patiently wait for the treesitter
indenting to become better than Vim's one.
In summary, at least for R and Quarto:
treesitter
than with Vim's syntax scripts.treesitter
.I see - all makes sense now. Hopefully the unmaintained Vim indentation will suffice to carry things over until treesitter indentation matures.
Many thanks again!
Just chiming in, I am using this to help me with indentation.
return {
"Wansmer/treesj",
keys = {
{
"<leader>m",
"<CMD>TSJToggle<CR>",
"Toggle Treesitter Join",
},
},
dependencies = { "nvim-treesitter/nvim-treesitter" },
config = function()
require("treesj").setup({
max_join_length = 240,
})
end,
}
In summary, at least for R and Quarto:
- Syntax highlighting is better with
treesitter
than with Vim's syntax scripts.- We don't need complex features in ftplugin scripts if using
treesitter
.- Vim's indenting is still better in my opinion, but I'm tired of maintaining it.
sorry for digging this old thread.
When I write code in other languages: Java indent is taken care of by google-java-format. Rust indent is taken care of by rustfmt.
R indent is probably taken care of by styler or in the future a better formatter. It is quite tedious to write code to certain indent style. The formatter can already take care of it automatically.
What do you think?
One of the most important changes for me when setting up R.nvim was to change the default indentation style:
This changes the indentation behaviour from this:
To this:
People of course have different opinions about which style is better, so in my view it would be best to:
I'm enjoying this plugin so much - thank you for creating it and generously making it available to the world!