I have a terminal buffer with 10000 lines of previously executed output. In order to search for the particular sequence of words I have to go through all 10000 lines before getting to my last executed command's output. Which makes me so annoyed. Is the a way of clearing a terminal buffer without quiting the terminal and running it again (because I use ssh to remote server and it's painfull to execute all the commands all over again to establish the connection to it). (settings scroll back to 0 or whatever won't do a trick)
AFAIK, there's no "good" way to do it, but there is a "hacky" way. Suppose you want
<c-w><c-l> combination to clear vim internal buffer in both normal and terminal(insert) modes. The mappings in vimrc would look like this:
nmap <c-w><c-l> :set scrollback=1 \| sleep 100m \| set scrollback=10000<cr> tmap <c-w><c-l> <c-\><c-n><c-w><c-l>i<c-l>
This will "clear" the buffer, and return you to terminal "insert" mode if necessary. Extra
<c-l> at the end is to also clear the shell screen, feel free to remove if you wan't need that. Note the sleep, which is required for it to work. Maybe it's possible to use a lower value than 100m, I'm not sure.
For a neovim/nvim/neo-vim this function and mappings can help:
vim.api.nvim_set_keymap('t', '<C-l><C-l>', [[<C-\><C-N>:lua ClearTerm(0)<CR>]], mapping_opts) vim.api.nvim_set_keymap('t', '<C-l><C-l><C-l>', [[<C-\><C-N>:lua ClearTerm(1)<CR>]], mapping_opts) function ClearTerm(reset) vim.opt_local.scrollback = 1 vim.api.nvim_command("startinsert") if reset == 1 then vim.api.nvim_feedkeys("reset", 't', false) else vim.api.nvim_feedkeys("clear", 't', false) end vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<cr>', true, false, true), 't', true) vim.opt_local.scrollback = 10000 end