kassio/neoterm

Neoterm goes back to empty buffer instead of last buffer

collegeimprovements opened this issue · 12 comments

Describe the bug
Environment: Neovim - 0.4.3

To Reproduce
Steps to reproduce the behavior:

  1. Opened a neoterm with :Ttoggle
  2. Toggled it wiht :Ttoggle
  3. It opens empty buffer, instead of going to the buffer from which it was invoked.

Expected behavior
It should go back to the buffer from which it was invoked.

Additional context
Add any other context about the problem here.

Thanks for your issue. Can you add any configuration you might have for the neoterm, please?

Here's my whole neoterm config:

" NeoTerm
" set nocompatible
" filetype off
" let &runtimepath.=',~/.vim/bundle/neoterm'
" silent! helptags ALL

let g:neoterm_autoscroll = '1'
let g:neoterm_size = 16
let g:neoterm_default_mode = ':vertical'

nnoremap <leader>tt :Ttoggle<CR>
nnoremap <leader>tt :Ttoggle<CR>
nnoremap <leader>tl :TREPLSendLine<CR>
nnoremap <c-l> :TREPLSendLine<CR>
nnoremap <leader>ts :TREPLSendSelection<CR>
vnoremap <leader>ts :TREPLSendSelection<CR>


" Use gx{text-object} in normal mode
nmap gx <Plug>(neoterm-repl-send)

" Send selected contents in visual mode.
xmap gx <Plug>(neoterm-repl-send)

" Send lines to Neoterm repl
nmap gxx <Plug>(neoterm-repl-send-line)



kvalv commented

I also have the same issue and am happy to see an issue on it already.

Generally, being able to do :<id>Topen and then <C-o> to go back to original buffer is desirable (and expected behaviour). Instead I have to do <C-o> twice to get back to the original buffer, so it seems that an intermediate empty buffer is created.

Ttoggle opens a new empty buffer each time I execute it.

EDIT: Actually I believe the problem is Topen because it has the same problem and Ttoggle executes Topen in the background.

The problem is this line

It was introduced with the commit cb685fd because of the issues #236 #262. Before this commit the command Topen would replace the current buffer with a new terminal-buffer if a terminal didn't already exist. Reverting this commit solves this issue for me. However, then Topen replaces again buffers.

Let's try to call @kassio

Can anyone confirm if the PR fixed the issue, please?

Well I can confirm. I am using it since I opened the PR. Isn't it working for you?

On my flow I don't have this bug. I'll close the issue then.
Thanks for the Pull Request, most appreciated!

@collegeimprovements I just noticed that, actually, your config has two typos:

let g:neoterm_autoscroll = '1'
let g:neoterm_size = 16
-let g:neoterm_default_mode = ':vertical'
+let g:neoterm_default_mod = 'vertical'
  1. It's mod, instead of mode
  2. the value must not include :

@astier, thanks again for the pull request, but it was actually highjacking empty buffers, so I reverted it.

pull request was actually highjacking empty buffers

What do you mean by this? It was making sure no empty buffer is created. Was it causing any issues for you?

On my flow I don't have this bug

I figured out that its caused when hidden is set. I guess then the empty buffer preserves. If hidden is not set it gets deleted. Maybe that's the reason why you don't have this bug. I have below some instructions how to reproduce it.

Minimal vimrc

cal plug#begin($XDG_DATA_HOME.'/nvim/plugins')
Plug 'kassio/neoterm'
cal plug#end()
set hidden

Steps to reproduce

  1. echo foo > foo
  2. nvim foo
  3. :Topen | b# | Topen | ls<cr>

Actual Behavior

The last command ls shows that besides foo also a second empty buffer with the name [No Name] exists.

Expected Behavior

No empty buffer should be created.

Cause of the Problem

The commit cb685fd makes the function s:create_window create a new empty buffer which doesn't get deleted when hidden is set.

Thanks a lot @kassio :) It's fixed.