tags:

views:

68

answers:

1

I would like to set up a vim environment for basic HTML edit to be used by someone else. For this I'd like to set up a quick reference bar to be shown on top of the window with things like

|   <F1>   |   <F2>   |  <F3>  |  ...
|  <br />  |  <hr />  |  bold  |  ...

and so on. Can this be done?

+5  A: 

You can use additional window with scratch buffer to show things like this.

Here is prototype of the plugin. Just run the following with :so or put this into some file inside

~/.vim/plugin

directory

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()
Mykola Golubyev
Thanks! That's actually a very good idea, just one thing with your show_help() function: I get an error trying to set the name to 'HTML help', vim complains about needing just one file name: using one single word fixes that. Also, how can I have the help window keep its height fixed no matter what happens to the other ones?
kemp
I am not sure you can force Vim to freeze window height. I escaped 'space' in buffer name. You can try this variant.
Mykola Golubyev