Skip to content

Instantly share code, notes, and snippets.

@thinca
Created November 19, 2011 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinca/1378839 to your computer and use it in GitHub Desktop.
Save thinca/1378839 to your computer and use it in GitHub Desktop.
" Edits vim variables in buffer.
" Version: 1.0
" Author : thinca <thinca+vim@gmail.com>
" License: zlib License
if exists('g:loaded_editvar')
finish
endif
let g:loaded_editvar = 1
let s:save_cpo = &cpo
set cpo&vim
function! s:save(var)
let {a:var} = eval(join(getline(1, '$'), ''))
setlocal nomodified
endfunction
function! s:editvar(var)
if exists(a:var)
let value = eval(a:var)
else
let value = ''
endif
if exists('*PP')
let v = PP(value)
unlet value
let value = v
endif
new `='editvar://' . a:var`
setlocal filetype=vim buftype=acwrite
if exists(a:var)
put =value
endif
let b:editvar_name = a:var
augroup plugin-editvar
autocmd!
autocmd BufWriteCmd <buffer> call s:save(b:editvar_name)
augroup END
endfunction
command! -bar -nargs=1 -complete=var Editvar call s:editvar(<q-args>)
let &cpo = s:save_cpo
unlet s:save_cpo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment