akinsho / toggleterm.nvim

A neovim lua plugin to help easily manage multiple terminal windows
GNU General Public License v3.0
4.4k stars 174 forks source link

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

Open jugarpeupv opened 2 months ago

jugarpeupv commented 2 months ago

Is there an existing issue for this?

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

hmgle commented 5 days ago

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:

jakeschurch commented 22 hours ago

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,
})