2

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?

  • That does require exiting picocom, which is what I am trying to get around. – user1135541 Jun 23 '16 at 17:14
  • Are you, by any chance, looking for :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.) – grochmal Jun 23 '16 at 19:52
3

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

Explanation:

The 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 (w0 and 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.

Caveats:

  • Neovim's highlighting won't overrule colors set by terminal's output. Since picocom doesn'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.

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.