toggleterm.nvim icon indicating copy to clipboard operation
toggleterm.nvim copied to clipboard

[BUG] Takes too much time to open terminal if the buffer is large

Open jugarpeupv opened this issue 1 year ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

If i run tree / in a normal :term buffer i can open it instantly, however if i do it with toggleterm then it takes a lot of time to open the terminal

Expected Behavior

It takes the same time than :term command

Steps To Reproduce

Install plugin, run tree / wait for the screen to load a lot of text, then toggleterm and the time it takes to open is very large

Environment

- OS:
- neovim version:
- Shell: zsh

Anything else?

No response

jugarpeupv avatar Sep 13 '24 19:09 jugarpeupv

I found this issue that seems to be related to the foldexpr. After commenting out the following configuration, the performance returned to normal:

vim.wo.foldmethod = 'expr'
vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'

Related issues:

  • https://github.com/nvim-treesitter/nvim-treesitter/issues/1100
  • https://github.com/neovim/neovim/issues/23964

hmgle avatar Nov 10 '24 03:11 hmgle

Can confirm this indeed fixed my issues with toggleterm

@akinsho - if you would have any interest in me adding a fix for this issue, I would be more than happy to open a PR to add an autocmd here to disable foldexpr for terminal to fix this issue. If not, no worries 👍

I've added this to my config, and would refactor slightly for PR if change wanted.

vim.api.nvim_create_augroup("disable_folding_toggleterm", { clear = true })

vim.api.nvim_create_autocmd("FileType", {
  group = "disable_folding_toggleterm",
  pattern = "toggleterm",
  callback = function(ev)
    local bufnr = ev.buf
    vim.api.nvim_buf_set_option(bufnr, "foldmethod", "manual")
    vim.api.nvim_buf_set_option(bufnr, "foldtext", "foldtext()")
  end,
})

jakeschurch avatar Nov 14 '24 21:11 jakeschurch