Thursday, August 12, 2010

Vim buffer execution

Currently toying around with Vim's scripting language. Have to know your favorite editor, don't you?

Anyway, the script I just completed is saving and sourcing the current buffer. Should prove useful for further Vim script development cycles.

The actual function looks like this:

" 2010-08-11..2010-08-13
" Saves current buffer and executes it.
" If the buffer doesn't have a filename, it is stored in a temp location.
function! SF_run()
if bufname("%") == ""
let PATH = "/tmp/".localtime().".vim"
else
let PATH = bufname("%")
endif
exec ":write ".PATH
exec ":source ".PATH
endfunction
map <F8> :call SF_run()<CR>
view raw exec_buffer.vim hosted with ❤ by GitHub

No comments:

Post a Comment