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 (backtick instead of single quotes) 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 convenient – D. Ben Knoble Jun 23 '21 at 12:16mxbefore 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... – raylight Jun 23 '21 at 14:25: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? – raylight Jun 23 '21 at 14:27:terminal bash %,:terminal node %, etc. You might have to use%:pfor a full path to execute directly. – D. Ben Knoble Jun 23 '21 at 14:55:terminal bash %on the bash file from my question but I still received the errorbash: file.bash: No such file or directory. – raylight Jun 23 '21 at 18:19file.bashexist in:pwd? – D. Ben Knoble Jun 23 '21 at 18:58:terminal bash %is exactly what I need here... Sorry, I don't know what I did wrong when I tested it in the afternoon, but I did something wrong probably... I'm testing it now and it works fine. – raylight Jun 24 '21 at 02:17