I have a
nofile buffer that contains vimscript, and I want to execute it. However,
:so % will not work because it requires a saved file, not a buffer. Is there a vim command to do this by default? If not, is it possible to create a function which does the same things?
Yes, you can yank the whole buffer with
:%y and execute it with
Used in a mapping:
nnoremap <key> :%y|@"<CR>
Used in a flexible command that works on the whole buffer by default or an optional range:
command! -bar -range=% Foo execute <line1> . ',' . <line2> . 'y|@"'