From my two previous questions, I learned about using :source %
, @"
, and other tricks to execute vimscript.
But as I noticed, :source %
needs the file to be saved first, furthermore, @"
and any other trick using registers don't always work.
Not needing to save first to execute something is very important for debugging/testing your code (as I'm sure many are already aware).
So is there truly no way to execute Vimscript (without as much restrictions as using registers has) without saving first?
:w | source %
. This answers your use case, but for the sake of knowledge (much more important :P), it does not answer question. I am searching for a way to use something like thesource
command on a buffer instead of a file, now. Cool question :):@*
.execute getline('.')
(or joining the lines and exec’ing), I’m not aware of anything. And those two usually have issues with line continuations/command separators.:source
; it's just written in the short formso
. In my experience, writing the code in a tempfile does not cause issues; they should be automatically removed as soon as you quit Vim. There are other similar techniques. If you use tmux, you can run the code in another pane, which is especially useful when you're trying to debug a crash (I'm doing it right now); you don't want your main Vim instance to crash.