Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run scripts in background in Neovim?

Tags:

vim

neovim

I wish I could mimic original VIM behaviour by running scripts in the background and not in the internal Neovim terminal emulator.

Basically the reason is that I cannot seem to get colors to work properly, plus, I like to Ctrl+Z (put the editor in the background) and check what was the output of the last command.

Anyway I can configure nvim to do the same as vim in this regard?

Here is the comparison:

EDIT: My tests are run by using :! ./vendor/bin/phpunit {file}

VIM

enter image description here

NVIM

enter image description here

EDIT

By "Background" I mean, not async, in the background while Neovim is on the "top". I mean, to place the editor in the background (like when we do ctrl+z, and then run the tests "on top". Then I hit a key and Neovim comes back to the top.

In other words, I want to configure nvim in a way that when I run a test, it is the same as doing CTRL-Z; execute test.

Sorry, this may be super confusing :D

like image 444
Marcelo Avatar asked Nov 08 '22 17:11

Marcelo


1 Answers

Instead of using :!{cmd}, I'd encourage you to experiment with running the tests via the :te[rminal] {cmd} command:

:te ./vendor/bin/phpunit {file}

That way the output from phpunit will be captured in a terminal buffer. You can switch between the terminal buffer and the test file using <C-^> (or :b#). Or you can open the terminal buffer and the test file side by side in separate windows. When you're finished with the terminal buffer, you can delete it using :bwipeout {num}.

One cool feature of terminal buffers is that if you place your cursor on a filepath and press gf, Vim will open the specified file. Better still, you use gF, then Vim will open the file at the specified line/column number, if those are present.

For more info, look up :help terminal in Neovim.

like image 111
nelstrom Avatar answered Nov 15 '22 06:11

nelstrom