4

Vim's new :term feature is pretty neat, but when I run something like a rails server, I want to be able to clear logging output every now and then.

The usual methods in a non-vim term window don't seem to work. Super-k, etc.

C-w :Clear<CR> seems to be for something different as well.

If I weren't running a rails server, I could just type clear in the terminal.

I glanced through help :term, not seeing what I want jump out at me.

  • Isnt <C-l> the standard clear key? – D. Ben Knoble Nov 16 '18 at 20:43
  • C-l is redraw. C-l actually does look like it clears the term window in Vim, but inconveniently it does not work when you have a process like rails server running. It has to be implemented by vim itself, because obviously if I use the terminal's actual clear key, it will wipe the whole screen including vim (which of course comes back if I hit C-l to redraw). Perhaps this is just an edge case the new feature just hasn't addressed yet. Because it should be simple. You also can't <C-\><C-n> and delete the text, because modifiable is off and cannot be turned on for a running process. – Wumbo Nov 16 '18 at 23:15
  • Bizarre... if i do :term and then press <C-l> in my spawned shell it clears the term screen – D. Ben Knoble Nov 16 '18 at 23:24
  • Yes, but try that after starting a process that needs C-c to end. Or just do sleep 10000 and try to C-l before it is done. This is actually the case for a non-vim terminal as well. – Wumbo Nov 16 '18 at 23:27
  • Well sure, the term never gets the clear. Hmm. I see the issue now – D. Ben Knoble Nov 16 '18 at 23:29
0

Going through Vim's terminal.txt, I don't think you have a chance to clear the window.

It's because Vim doesn't do anything about <c-l>, just passing it as well as other typed keys to the running job, like bash or rails server. (when your focus is in the window)

The <c-w>:clear doesn't do the trick, either. The command is abbreviation of :clearjumps for newer Vim versions.

For normal terminal, like gnome-terminal or mac's terminal, it's the terminal dealing with your <c-l> or <cmd-l>, <cmd-k>. Vim's terminal looks not doing it.

However, I happened to try out a workaround. You can try it for your environment:

:tmap <c-l> <c-w>s<c-w>c

  • tmap is mapping specific for terminal job mode.
  • <c-w>s creates a new window, and when <c-w>c closes it and gets back, the terminal is cleared.
  • Sorry, but c-w s c-w c also does not work. You can try with sleep 10000. Text for processes in progress is not lost. There's probably situations where that is desirable. I agree, there are commands that vim is interpreting, and commands that the terminal app is interpreting. :clear and :Clear are different. vim terminal has some idea about breakpoints. I'm not entirely sure what it is about. – Wumbo Nov 17 '18 at 13:53
  • Let's check the version: I tested it with Vim 2.8.0 on ubuntu 18.04. However, I don't have gui on this server. I 'ssh' to the server and launch 'screen' to work with. Both sides are gnome-terminal. I don't understand why you test with "sleep 10000". It doesn't have anything on screen for your to CLEAR. (If you run it by ":term sleep 10000".) I test with ":term tail -f /var/log/syslog", which spit out log info from time to time. It works very well. – Charles Jie Nov 17 '18 at 16:47
  • sleep is just an example of a long running process for someone who isn't using rails server or similar. Start :term without an argument. type echo 'test'. type sleep 10000. tail gives output instantly, so it's not a good example. You don't have to remap <C-l> for tail, it would work already because it is finished quickly. – Wumbo Nov 17 '18 at 22:15
  • There is some misunderstanding. Tail with option '-f' (follow) will track a growing file and keep printing to the screen. It's a good way to simulate the so-called 'log' behavior of a server. You can either test with it directly via :term tail -f GROWING_FILE or run it in the bash called :term. – Charles Jie Nov 17 '18 at 23:22
  • In addition, tail -f will never come back until you press <ctrl-c>. It's better than sleep 10000 because it has output from time to time. – Charles Jie Nov 17 '18 at 23:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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