Let's say I have a file with the following bash code:
echo "line 1"
echo "line 2"
echo "line 3"
echo "line 4"
echo "line 5"
echo "line 6"
echo "line 7"
echo "line 8"
echo "line 9"
echo "line 10"
echo "line 11"
echo "line 12"
echo "line 13"
echo "line 14"
echo "line 15"
Let's also say that I'm editing the line 11, if I use the command :!% bash
I'll execute this file and its output will substitute the current file that I'm editing. So I can use Vim for navigating on its output and then I can press u
for going back to what the code file was originally...
So far everything is fine, except for the fact that when I press u
it sends the cursor back to line 1. I know I can set a marker on the line that I'm editing before executing it, something like ma
and then 'a
or `a
to go back to the line that I was... But that becomes troublesome doing it all the time...
I also know that I could execute the file with :set makeprg=bash\ % | make
while seeing its output on the terminal, but in this way, I won't be able to navigate on the output with the Vim editor, and that's a functionality I'd like to keep... Is there any way of executing a file from inside Vim, see its output and edit it with Vim, while also being able to go back to the original code on the same line that I was?
:terminal %
may be more convenientmx
before executing the code all the time... I often forget to create the marker when I'm executing the code many times and then I can't go back to it with'x
. So my main criteria here is to go back to the liine that I was without having to remember to create this marker before executing the file. If there is a command that I can do it without having to create the marker that would be enough... But in this case, using''
doesn't work as well...:terminal %
my screen splits and I see the messageexecuting job failed: No such file or directory
, where my only choice seems to be going out of it with:q
. I'm not sure if I'm missing something. Did you mean just typing:terminal %
from inside the node.js file that I'm editing?:terminal bash %
,:terminal node %
, etc. You might have to use%:p
for a full path to execute directly.