10

One big difference of neovim and Vim is that neovim includes a terminal emulator that works asynchronously.

However, I fail to see how can I profit from this feature. For what can I use it? Can you give some use cases for neovim's terminal feature so that I understand how I can use it to its best extent?

In normal Vim I normally use :read !{command}, :write !{command}, Ctrl+Z and fg as well as tmux split windows.

6
  • One problem with <C-z> is that the Vim process is suspended by the OS: it's not doing anything (including responding to server commands). Sep 4 '15 at 15:15
  • Would it help to use :shell with exit instead or is vim suspended here too?
    – cbaumhardt
    Sep 4 '15 at 15:18
  • 1
    @Carpetsmoker, what do you expect your text editor to do when you are not using it?
    – romainl
    Sep 4 '15 at 15:35
  • @romainl Well, for example I have a script which will focus the Vim session editing a particular file; this will hang on suspended Vim processes... Sep 4 '15 at 15:39
  • 1
    That's not a problem with <C-z>, that's a problem with your script.
    – romainl
    Sep 4 '15 at 15:56
10

Running a terminal inside Vim allows you to use Vim commands on the input and output to the programs that you run in that terminal. You get search, copy-paste, macros, syntax coloring, etc. Using :read !{command} and :write !{command} gives you that for one-shot commands, but asynchronous input/output becomes useful when you want to submit input to an external program piece by piece.

The typical use case is a read-eval-print loop (REPL), which is provided by many high-level programming languages. You type a stanza in your source code, then feed it to the REPL for immediate feedback. Since the REPL keeps running from one submission to the next, the submitted code snippet are executed in context.

6

I think the option to create terminal-only mappings is valuable, and extends the options you've got in other terminal emulators, e.g. mapping t to run unittests with specific configuration, which you can only achieve through complex aliases or bash functions.

4

The most obvious use case I can think of is programming. Have you ever wanted to run tests inside VIM, or compile, or use any console tool? I know people use Tmux, but know that you can do it inside NeoVIM I have to say. This is pretty awesome !!!

If you use buffers you can add, remove, hide and show terminals as you please. That's the profit ;)

Running a shell inside NeoVIM

3

The best use case I can think of is the original one-an ADM-3a on a 110 bps line! Sometimes there's really no substitute for looking at things side-by-side, and :!r doesn't cut it.

1
  • 3
    Good luck getting anything done in two 39x12 (or 39x24!) windows ;-)
    – romainl
    Sep 5 '15 at 13:47
1

One particular use case I had experienced was conservation of my development environment in a different terminal emulator. At the time, I needed to change my terminal emulator to xterm which does not support tabs, as far as I know. I was use to having this feature from gnome-terminal. However with a terminal emulator inside neovim, I was able to open new tabs inside neovim and launch terminal emulators from there, thus mimicking closely my old work environment.

1
  • Welcome to Vi and Vim! Yes this is a valid use case for Vim/NeoVim terminal, though if strictly having multiple shells is the reason for using it, then other tools such as tmux or screen might be more appropriate. The main advantage of using it from Vim/NeoVim (over those tools) is deeper integration with the editor, such as splitting between editor and terminal (doable in tmux/screen, but cleaner with Vim/NeoVim terminal) and launching commands from the editor, such as building or running code from current buffer.
    – filbranden
    Jul 8 '20 at 2:20

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.