Vim Tip #16: A Terminal Inside (Neo)Vim

2018-12-01(Sat)

tags: Vim

Vim Tips

Vim has - or had, it's no longer supported - the "Conque" plugin to create a terminal inside Vim. I found it buggy and problematic.

The appearance of the NeoVim fork was a kick in the pants to the Vim project that's spurred development in both projects. NeoVim added a built-in terminal that was far better than Conque. Vim, as of version 8, has the same thing.

In Vim, just type :terminal or simply :term. It will create a split window with a terminal in it.

To do the same thing in NeoVim, start a new tab (Normal Mode :tabnew and Enter) then in Normal Mode type :term. I'm recommending a new tab because the NeoVim terminal startup behaviour is different than Vim, with the :term command taking over your current buffer.

I'm occasionally finding that the terminal session doesn't read all the start-up commands I expect it to (sometimes some of my aliases or functions aren't defined), but for the most part it's great. It takes a bit of time to learn/remember that you need to type a (or A, i, A, or probably any command that puts you in Insert Mode) before you can type shell commands, and likewise you have to learn to hit <Esc> to go back to Normal Mode to be able to change tabs again. But once you remember that, there are some really interesting side effects such as easy Normal Mode scroll-back, and all your standard Vim commands to search or yank text from your shell session.

There's one caveat: DON'T forget you're inside (Neo)Vim and try to edit a file with (Neo)Vim. It's NOT pretty. I kind of wonder why the NeoVim authors haven't addressed this, trapped the nvim startup, and thrown it into a new tab or buffer of your current NeoVim session. Maybe that's harder than I think it is. Regardless, don't try it - you'll end up being forced to exit ugly.