zbirenbaum / nvterm

NvChad's Official Terminal Plugin ( Unmaintained but still usable and stable), wait for v3.0
GNU General Public License v3.0
181 stars 20 forks source link

Toggleable & spawnable terminal window buffer #6

Open siduck opened 2 years ago

siduck commented 2 years ago
 mappings = {
    toggle = {
      float = "<A-i>",
      horizontal = "<A-h>",
      vertical = "<A-v>",
      window = "<A-w>"
    },
    new = {
      horizontal = "<C-h>",
      vertical = "<C-v>",
      window = "<C-w>",
    },
  },
siduck commented 2 years ago

Spawnable term window could be like :

:execute 'terminal' | let b:term_type = 'wind' | startinsert <CR>"

idk if it would be possible to toggle a term window buffer

zbirenbaum commented 2 years ago

this is functionally equivalent to just doing :term I can take a look at enabling this so things like sending commands to the term works after finals some time next week.

FYI: Buffers aren't windows. Neovim terminology is very specifc, this really confused me until I remembered you use bufferline....

siduck commented 2 years ago

yes ik its :term, but it would be nice to toggle it and hide it too :thinking:

image

zbirenbaum commented 2 years ago

This is because it fundamentally is not how windows function. Buffers are not windows.

I know how to implement this, but both can't until next week, and am not sure I should given that functionally there's no difference between this and literally doing C-z running your command in the normal term, and then fg to resume.

In fact, doing suspend and resume strategy is actually much better since native term is much faster than neovim emulator.

siduck commented 2 years ago

C-z exits nvim

image

zbirenbaum commented 2 years ago

C-z exits nvim

image

This is not true. C-z suspends a program to the background. Run 'fg' (foreground) and it will come back up exactly where it left off.

It's equivalent to creating a new tab page or something which is what you refer to as a "window"

faraazahmad commented 2 years ago

Is this issue related to functionality where toggle opens a new terminal if not already open?

siduck commented 2 years ago

Is this issue related to functionality where toggle opens a new terminal if not already open?

no, this is for toggling new terminal window ( listed ) if thats possible @zbirenbaum

zbirenbaum commented 2 years ago

Is this issue related to functionality where toggle opens a new terminal if not already open?

no, this is for toggling new terminal window ( listed ) if thats possible @zbirenbaum

Again, what you are referring to here as a window is actually a buffer. The implementation of the behavior you are describing would be to replace the buffer in the current window with a terminal and then restore it on toggle. I just took some time to see how it would have to be implemented and came across a few problems.

  1. This leads to all sorts of messy stuff to save and restore the window options since things like eolchars, linenumbers, etc will all have to be changed when the terminal is opened, and then restored when it is closed.
  2. If the user does anything to close the terminal other than use the dedicated toggle function, it would make a mess of everything and cause tons of bugs.
  3. Due to 1 & 2, I would then have to write autocmd's and do a ton of state tracking that is currently unnecessary
  4. The only people who could feasibly have a use for this are those who use bufferline and plugins like it.

This would make much more sense if it opened in a new tabpage, which would actually provide the behavior you want and have none of the above issues, but would not integrate with the plugins that treat buffers as tabs. For that reason, while I am happy to implement this with a tabpage,

I don't want to do this the way you are thinking about it, as it:

  1. Encourages bad habits
  2. Exacerbates confusion between what a buffer and a window actually are
  3. It is about 10x more work than quite literally any other feature would require to implement due to the debugging I foresee it requiring.

It isn't undoable, so if it would really mean a lot to you to have this feature, I am willing to put in that effort to write it at some point, but I am going to have to give priority to some other features I am working on in other repos at the moment.

If you want the tabpage implementation, it would be extremely quick to write, and I can do it immediately.

@siduck Let me know your thoughts, and please read this carefully, as all of the above info is relevant.