我想设置一个 vim 环境以供基本的 HTML 编辑使用 由其他人。为此,我想设置一个快速引用栏以 显示在窗口顶部,类似
| <F1> | <F2> | <F3> | ...
| <br /> | <hr /> | bold | ...
等等。这能做到吗?
最佳答案
您可以使用带有暂存缓冲区的附加窗口来显示此类内容。
这是插件的原型(prototype)。只需使用 :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()
关于VIM:在窗口顶部显示自定义引用栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1741139/