Update: It is possible with '<,'>source
.
I figured it out right after writing this question, no need for the complicated workaround. I am gonna still let this question here and not delete it, maybe this will help someone out :)
Question
Is it possible to select the VimL
part and execute it somehow?
Setup
random.txt
file:
this is just a random text file
for example here are my notes
hello world
My VimL:
for i in range(3)
echo i
endfor
some more useless text
end of this useless file
Note: This is just a text file, not a vim file
My Idea
This is a workaround that works, but isn't too fancy:
'<,'>w! /tmp/%:t.vim | source /tmp/%:t.vim
Explanation:
'<,'>
: Is the selected text as a rangew!
: write command with!
to overwrite in case file exists already/tmp/%:t
: This is probably the most complicated thing, but here it is broken down:/tmp
: dir to write the file into%:t
: takes the current filename, but only the tail (/home/user/Downloads/random.txt
->random.txt
).vim
: add a.vim
extension. Not needed, but makes it more clearsource /tmp/%:t.vim
: finally source thetemporary file
Thank you for your help :)
+12
rep. A win-win :)reputation
and it would be deserved to give you somereputation
for that... But okay :)