1

I recently decided to give a try at neovim and one thing is bothering me:

I use a terminal window to run my code watcher i.e. a never ending command which outputs new lines each time I write a buffer.

If I put my cursor on this window and use G the window will keep track of the output and I will always see the last lines of the output as long as I don't switch of window.

If I change of tab or of window, the window containing the terminal buffer stops scrolling and I have to go back to this window and use G again to see the end of my output.

If feel like I'm missing something but I wasn't able to find a solution to this problem. I guess I could have an autocommand on TabEnter and for example which would find a terminal buffer in the new tab and use norm! G in it but that feel kind of overkill (plus that wouldn't solve the problem if I have two split buffer and I work on the one next to the terminal buffer). Is there a simple solution to this problem?

EDIT Here are the steps to reproduce my issue:

Create a file and continuously write in it from the shell:

  • touch foo
  • while; do; echo 'a' >> foo; sleep 1; done

Start neovim without any config:

  • nvim -u NONE -U NONE

In neovim:

  • :term tail -f foo To open a terminal with a continuous output
  • Go to insert mode and add an empty line to follow the output then go to normal mode and G
  • :tabnew

Wait a few seconds

When going to the first tab, the empty line should have changed of place, for me it doesn't.

2 Answers 2

2

EDIT The problem was actually a bug in neovim fixed by the commit 47b7b471fa which is now merged in master.


So after asking the Neovim issue tracker it turns out this is the current "expected" behavior of the code:

In terminal.c the function adjust_topline() iterates over FOR_ALL_WINDOWS_IN_TAB, changing that to iterate over FOR_ALL_TAB_WINDOWS fixes my issue.

I'm not sure of the implications regarding the performances of this change, but if the neovim community agrees I'll create a PR.

0

You can use this oneliner (from this answer, tnx eli)

:set autoread | au CursorHold * checktime | call feedkeys("G")

Explanation:

  • autoread: reads the file when changed from the outside
  • CursorHold * checktime: when the cursor isn't moved by the user for the time specified in updatetime (which is 4000 miliseconds by default) checktime is executed, which checks for changes from outside the file
  • call feedkeys("G"): the cursor is moved to the end of file

To stop the scrolling when using call feedkeys("G"), execute :set noautoread - now vim will tell, that the file was change ans ask if one wants to read the changes or not)

2
  • 1
    Thank you for your answer but it's not exactly what I want: If I reuse it as you posted it, it has a lot of side effects: autoread is set for every buffer and the autocommand too so every buffer will constantly jump to the end which is pretty annoying. So I tried to adapt it so that only term buffers are affected: autocmd CursorHold term//* checktime | call feedkeys("G") but then it works when I change of window but if I do tabnext (and tabprev again) the terminal buffer isn't updated anymore (I'm not sure why)
    – statox
    Jul 24, 2019 at 12:25
  • @statox you a right. Seems weird, but switching tab freezes autoscroll in term window. I tried :au FocusGained,BufEnter,TabEnter,CursorHold,CursorHoldI term//* if mode()!='c' | checktime | call feedkeys("G") | endif , but did not help
    – Yasen
    Jul 26, 2019 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.