I am using NeoVim terminal with picocom. Every so ofter, I would like to clear the terminal buffer/screen inside the NeoVim terminal without exiting picocom, is there a short cut that clears the NeoVIM terminal buffer?
What you want isn't possible.
picocom would need to clear the screen, but it's not a curses program so it can't. If you want to declutter the screen so you can stay focused on new output, you can "clear" what's on the screen by modifying the colors of what's displayed in the terminal window.
function! s:fake_clearterm() abort let top = line('w0') - 1 let bottom = min([line('$'), line('w$')]) + 1 silent! call matchdelete(1234) call matchadd('FakeClearTerm', '\%>'.top.'l\_.*\%<'.bottom.'l', 0, 1234) endfunction highlight default FakeClearTerm ctermfg=234 ctermbg=16 guifg=#333333 guibg=#000000 tnoremap <silent> <c-l> <c-\><c-n>:<c-u>call <sid>fake_clearterm()<cr>i
FakeClearTerm highlight group sets a dark gray foreground and black background which dims the text. You would have to adjust this to match your color scheme.
s:fake_clearterm() gets the terminal window's top and bottom lines (
w$ respectively). Then it creates a pattern matching any line within window and applies the
FakeClearTerm highlight group to it. The match is given a priority of
0 which allows searches to highlight text within the dimmed text. The match ID
1234 is arbitrary.
ctrl-l is used to "clear" the text. It's using
tnoremap which means it has to be used in the terminal's insert mode. In normal mode
ctrl-l redraws the screen.
After "clearing", new text below the matched region will use default colors.
- Neovim's highlighting won't overrule colors set by terminal's output. Since
picocomdoesn't print colors, this shouldn't be a big deal.
- Scrolling up is still possible and the text in the scrollback won't be dimmed.
- You have to
:call matchdelete(1234)yourself to remove the highlight.
picocom, which is what I am trying to get around.
:redraw!? I never used picocom, but i'm confident that
:redraw!is present in neovim. (the
!at the end of
:redraw!is to force the clearing of the screen before redrawing.)