Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to quit Node.js and launch VIM on a file?

I'm creating a simple terminal-based file manager on Node.js. Is there any way I can, from while my program is running on the terminal, quit it and open a file with VIM?

like image 620
MaiaVictor Avatar asked Feb 16 '23 23:02

MaiaVictor


1 Answers

Simply:

require('child_process').spawn('vim', ['test.txt'], {stdio: 'inherit'});

If there is nothing left in the Node.js event loop when vim exits, then node will exit automatically as well. Or, if you need to guarantee node will exit when vim does:

var vim = require('child_process').spawn('vim', ['test.txt'], {stdio: 'inherit'});
vim.on('exit', process.exit);

As for closing the node application before vim exits, that's not really possible because vim inherits standard input/output/error streams from the spawning process (node) which are destroyed when node exits.

like image 75
Bret Copeland Avatar answered Feb 19 '23 14:02

Bret Copeland