Created
November 19, 2011 13:34
-
-
Save thinca/1378839 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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