Neovim has a very handy terminal emulator.
In normal mode, I can use all the read-only vim commands on the output, like scrolling or going to the file under the cursor.
But more often than not, I want to delete some lines. Is it possible?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityNeovim has a very handy terminal emulator.
In normal mode, I can use all the read-only vim commands on the output, like scrolling or going to the file under the cursor.
But more often than not, I want to delete some lines. Is it possible?
You can use this mapping to copy the content of the terminal buffer into a new buffer:
tnoremap <C-U> <C-\><C-N>:%y \| vertical new \| normal! P<CR>
<C-\><C-N>
goes back to normal mode so you can use any normal mode command you want.
:%y
copy the content of the buffer.
vertical new
create a new vertical split.
normal! P
paste the previously yanked text into the buffer.
I'm too lazy to be bothered to manually re-enter term mode and then paste the output of @nobe4's solution above. I combined this with another keybinding in normal mode to accomplish insert, kill the current command with ctrl-c, enter term mode, paste and then insert.
"term stuff
" let C-U open a new buffer to edit the current terminal line
tnoremap <C-U> <C-\><C-N>:y \| vertical new \| normal! P<CR> \| ^dw
nnoremap <C-U> ^D \|:q!<CR> \| i<C-c><C-\><C-n>pi
" let ESC take out out of term mode
tnoremap <ESC> <C-\><C-n>
so C-U will do both steps.
:help CTRL-U
). Also, why does the normal mode map have space-escaped-bar after ^D
? Shouldn't that be ^D:q!<CR>i<C-c><C-\><C-n>pi
---and then why i<C-c>
? I think, for a terminal, that should be ^D:q!<CR>I<C-w>""
. And the tnoremap should maybe be <C-\><C-n>:yank \| vertical new<CR>P^dw
?
Just came across this plugin, which makes several normal mode commands available in terminal buffers: https://github.com/chomosuke/term-edit.nvim