Instructor: Terminal support was released in Vim 8. We can check for support by saying echo has('terminal'). If a 1 is returned, it's supported. If a 0was returned, it's not.
I have a project here with a package.json. I've opened a terminal in the current window by passing the ++curwin option to the terminal command. I can run commands in a live terminal. I can say npm list to show my dependencies.
I want to interact with Vim outside of this terminal, so I'm going to prefix my commands with CTRL-W. I want to open up a new split with the code from my project, so I'm going to say CTRL-W :, give it the command v new. In here, I can run commands as normal. I can just say :edit index.js.
In here, I have a few dependencies. I'm using Highland and Chalk. As we saw above, neither of these dependencies are installed. I can go back to the running terminal by doing CTRL-W l. I can give it the command npm install Highland.
I'm going to close this terminal by giving the exit command directly to the shell. That's going to close that window as well. I'm going to open up another split and say vertical new. I'm going to say terminal node index.js. This is going to run in a new terminal that's going to be opened up because I haven't passed it ++curwin as one of the options.
We can see here that we don't have Chalk installed. What I'm going to do now is I'm going to install Chalk, but I'm going to run the npm install command in a hidden job. I'm going to say terminal ++hidden npm install Chalk.
I could also give it the ++open option. That would hide the output from this terminal job until the job is finished, at which point it would open it. That's always a little surprising to me when that happens. It tends to break my flow, so I'm just going to leave this hidden. I'm going to let it close on its own. I'm going to forget about it.
Nothing seems to happen from here, but if I say terminal current window node index.js, now my code is running. According to the code on the right, I'm going to pass in a file name to std in. I'm going to say sample01.txt. That's a file that I know I have. We can see the contents of the file on the right. This is the first sample file. I probably have a sample02.txt.
Great. I can keep going with that. I'm still just going to be guessing what I have, unless I've remembered it. I'm going to close this command. Rather than guess in a shell, I'm going to generate a list of these files and pass them directly by running an actual command in a terminal. I'm going to say terminal find in this directory files whose names begin with sample. Here we go.
I'm going to select all these files, and I'm going to pass these as a range to the terminal command. I'm going to say range terminal node index.js. The selected lines are going to be passed directly to the job. You can see that the code on the right received each of these.