I want to edit files by executing Vim commands from inside node.js as the following:
const child_process = require("child_process");
child_process.execSync(`time vim /home/user/file -c ':%s/^/newstring-/g | x'`);
When I run this code I get the following result:
node vimCommand.js
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal
0.07user 0.00system 0:02.08elapsed 3%CPU (0avgtext+0avgdata 23168maxresident)k
0inputs+80outputs (0major+2611minor)pagefaults 0swaps
The functionality of this code works perfectly fine. However, for some reason, Vim is taking more than 2 seconds to execute this command in a very small file. That's not necessarily an issue with node-js because if I run echo commands instead, it executes immediately. Also, besides that, I've realized that when I use Neovim instead of Vim, this issue doesn't exist and my code works perfectly fine and fast:
node vimCommand.js
0.02user 0.01system 0:00.04elapsed 85%CPU (0avgtext+0avgdata 14164maxresident)k
0inputs+256outputs (0major+2218minor)pagefaults 0swaps
Here is the result of changing vim to nvim inside my node.js code. It doesn't have any warning telling me Output is not to a terminal. So, is there any extra procedure that nvim does automatically that I should manually do on vim? Just so it doesn't take too long to start executing the vim commands that I'm using? Or should I just consider it a vim bug and switch to neovim for doing this kind of stuff?
OBS1: When I run the command time vim /home/user/file -c 'execute ":%s/^/newstring-/g" | x' directly inside a terminal it executes very fast and I don't see any warnings. So the issue happens when I'm trying to use vim indirectly without a terminal window.
OBS2: the file I'm editing in my example is a very small one. My main issue here is why there's a 2 seconds delay for executing vim commands when I'm not running it directly from a terminal.
OBS3: I know that for this example I could just have used sed on the command line for doing exactly the same thing that my example is doing. But that was just an example for illustrating the problem, and executing ":%s/^/newstring-/g" is not the main issue.