Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute the contents of a buffer?

Tags:

vim

I have a vim script I'm developing in my current buffer and I want to execute it. Is there a simple way to do it?

After a long search I have only found two related ways, but not exactly what I'm looking for:

  • a) "source" command - but to use it I first need to save the content to file and then "source" it back, which doesn't look simple

  • b) "call" command - but I don't want to call my function, I want to execute the whole file, which defines several functions and has some code outside of functions at all

like image 604
lithuak Avatar asked Mar 16 '11 14:03

lithuak


2 Answers

Use:

:%y"                      (alternatively: ggyG)
:@"

It will copy whole buffer into default register and then run it.

See :help :y and :help :@ (and also :help range maybe).

like image 191
Benoit Avatar answered Nov 01 '22 21:11

Benoit


An autocmd to source the file whenever you save might help:

autocmd BufWritePost <buffer> source %
like image 4
Raimondi Avatar answered Nov 01 '22 22:11

Raimondi