askfiy
February 17, 2022, 3:34pm
1
Many times we want to enter multiple parameters, so we have the following format:
func(
x = 1,
y = 2
)
When pressing enter after line 4), line 5 should be indented to the front, not after 4 spaces:
func(
x = 1,
y = 2
)
| expected
| actual
Below is my configuration, what should I do to make it work as expected?
vim.o.filetype = "plugin"
python.lua:
vim.bo.expandtab = true
vim.bo.shiftwidth = 4
vim.bo.tabstop = 4
vim.bo.softtabstop = 4
dchuri
February 17, 2022, 4:22pm
2
I’m pretty sure you have treesitter indenting enabled, I would suggest disabling it entirely or for python files only
askfiy
February 18, 2022, 6:18am
3
Yes, this works.
In addition to this, I want to implement another function, do you know how it should do it.
for example:
def func(x, y):
print(x, y) <CR>
| <BS> <CR>
| expected
| actual
I can describe it more intuitively with a dynamic graph:
I want the indentation to always keep the indent amount of the previous line, if the previous line doesn’t have any indentation, the next line shouldn’t be indented either, shouldn’t it?
dchuri
February 18, 2022, 6:35am
4
I can’t seem to reproduce this, I get your expected result. Are you sure you’ve disabled treesitter indentation for python files?
askfiy
February 18, 2022, 1:59pm
5
Yes, but I disabled the indentation of the treesitter I now want it to work like the diagram, here is my treeitter config:
require("nvim-treesitter.configs").setup(
{
ensure_installed = "maintained",
sync_install = false,
highlight = {
enable = true,
additional_vim_regex_highlighting = false
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<CR>",
node_incremental = "<CR>",
node_decremental = "<BS>",
scope_incremental = "<TAB>"
}
},
indent = {
enable = false
},
rainbow = {
enable = true,
extended_mode = true
-- colors = {}, -- table of hex strings
-- termcolors = {} -- table of colour name strings
},
context_commentstring = {
enable = true
}
}
)
dchuri
February 18, 2022, 9:12pm
6
enable = false
is invalid, you need to use this instead:
Disable treesitter indentation entirely:
disable = true,
Disable treesitter indenting for python files only:
disable = { "python" },
1 Like
gwww
February 22, 2022, 11:33pm
7
I believe that enable = false
disables the entire indent module. This is documented in the README and code is here: nvim-treesitter/configs.lua at master · nvim-treesitter/nvim-treesitter · GitHub
I don’t believe that disable = true
is supported but disable = { <language>, ...}
is supported as you have written. The disable handling is here: nvim-treesitter/configs.lua at master · nvim-treesitter/nvim-treesitter · GitHub
dchuri
February 23, 2022, 4:44am
8
@askfiy already has enable = false
in his treesitter indentation config. It doesn’t seem to disable it for him, neither does it for me. disable = true
is supported, and that’s how you disable treesitter indentation entirely or independent languages. (Atleast that’s what works for me).
askfiy
February 24, 2022, 2:07pm
9
For me either disable = true or enable = false works equally well, but disable = {‘python’} doesn’t.
Also, the phenomenon in my second picture can’t be solved by this, I don’t know what to do,lol …
dchuri
February 24, 2022, 2:40pm
10
I really don’t think treesitter indentation is getting disabled for you. Can you try uninstalling the python parser entirely using :TSUninstall python
and see if the behavior you expect happens?