Skip to content

Instantly share code, notes, and snippets.

@rbtnn
Created December 7, 2013 07:40
Show Gist options
  • Save rbtnn/7838338 to your computer and use it in GitHub Desktop.
Save rbtnn/7838338 to your computer and use it in GitHub Desktop.
逆引きVim scriptなど
let g:vimtips#tips_dir = get(g:,'vimtips#tips_dir',expand('~/.tips'))
let g:vimtips#tipsfile_default_encoding = get(g:,'vimtips#tipsfile_default_encoding','utf-8')
function! s:contents_list() " {{{
let list = []
for x in split(globpath(g:vimtips#tips_dir,'*.*'),"\n")
let list += [{
\ 'path' : x,
\ 'title' : get(readfile(x),0,"null"),
\ }]
endfor
return list
endfunction " }}}
function! vimtips#selector() " {{{
new
let b:list = s:contents_list()
setlocal buftype=nofile nobuflisted noswapfile bufhidden=hide
setlocal filetype=vimtips
silent % delete _
silent put=map(deepcopy(b:list),'iconv(v:val.title,g:vimtips#tipsfile_default_encoding,&encoding)')
silent 1 delete _
setlocal nomodifiable
setlocal readonly
nnoremap <buffer> <cr> :call vimtips#open(b:list[line('.')-1])<cr>
endfunction " }}}
function! vimtips#open(contents) " {{{
if &l:filetype ==# 'vimtips'
bdelete
endif
new
setlocal buftype=nofile nobuflisted noswapfile bufhidden=hide
setlocal filetype=help
silent % delete _
silent put=map(readfile(a:contents.path),'iconv(v:val,g:vimtips#tipsfile_default_encoding,&encoding)')
silent 1 delete _
setlocal nomodifiable
setlocal readonly
endfunction " }}}
call vimtips#selector()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment