VIM:在窗口顶部显示自定义参考栏

时间:2009-11-16 09:49:22

标签: vim

我想设置一个vim环境,以便使用基本的HTML编辑 由别人。为此,我想设置一个快速参考栏 用

之类的东西显示在窗口的顶部
|   <F1>   |   <F2>   |  <F3>  |  ...
|  <br />  |  <hr />  |  bold  |  ...

等等。可以这样做吗?

1 个答案:

答案 0 :(得分: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()