2009-11-16 62 views

回答

5

您可以使用附加窗口和临时缓冲区来显示类似的内容。

这是插件的原型。只要运行与:so以下或投入一些文件,这里面

~/.vim/plugin 

目录

function! s:set_as_scratch_buffer() 
    setlocal noswapfile 
    setlocal nomodifiable 
    setlocal bufhidden=delete 
    setlocal buftype=nofile 
    setlocal nobuflisted 
    setlocal nonumber 
    setlocal nowrap 
    setlocal cursorline 
endfunction 

function! s:activate_window_by_buffer_name(name) 
    for i in range(1, winnr('$')) 
     let name = bufname(winbufnr(i)) 
     let full_name = fnamemodify(bufname(winbufnr(i)), ':p') 
     if name == a:name || full_name == a:name 
     exec i.'wincmd w' 
     return 1 
     endif 
    endfor 

    return 0 
endfunction 

let s:help_window_name = 'HTML\ help' 

function! s:show_help() 
    let current_name = fnamemodify(@%, ':p') 

    if ! s:activate_window_by_buffer_name(s:help_window_name) 
     exec 'top 5 split '.s:help_window_name 
     call s:set_as_scratch_buffer() 
    endif 

    setlocal modifiable 

    let help_lines = ['line1', 'line2'] 
    call setline(1, help_lines) 

    setlocal nomodifiable 

    call s:activate_window_by_buffer_name(current_name) 
endfunction 

command! -nargs=0 HtmlHelp call s:show_help() 
au! BufRead,BufNewFile *.html call s:show_help() 
+0

谢谢!这实际上是一个非常好的想法,只是你的show_help()函数有一件事:我试图设置名称为'HTML帮助'时出现错误,vim抱怨只需要一个文件名:使用单个单词修复该错误。另外,无论遇到其他问题,我怎样才能让帮助窗口保持其高度不变? – 2009-11-16 10:35:28

+0

我不确定你可以强制Vim冻结窗口高度。我逃过缓冲区名称中的'空间'。你可以尝试这个变种。 – 2009-11-16 11:48:22