VIM: display custom reference bar on top of window

两盒软妹~` 提交于 2020-01-02 08:12:27

问题


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?


回答1:


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()


来源:https://stackoverflow.com/questions/1741139/vim-display-custom-reference-bar-on-top-of-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!