dgy
/
hexagons
Archived
1
0
Fork 0
This repository has been archived on 2021-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
hexagons/.config/nvim/ftplugin/man.vim

104 lines
2.4 KiB
VimL

""
" Show table of contents window.
" Modified version of man#show_toc() and ftplugin/qf.vim's s:setup_toc().
"
" nnoremap <buffer><silent> gO :call man#showtoc()<Enter>
""
" setlocal statusline=
setlocal textwidth=80
function! man#showtoc() abort
let l:bufname = bufname('%')
let l:info = getloclist(0, { 'winid': 1 })
if !empty(l:info) && getwinvar(l:info.winid, 'qf_toc') ==# l:bufname
lopen
return v:true
endif
let l:toc = []
let l:lnum = 2
let l:last_line = line('$') - 1
while l:lnum && l:lnum < l:last_line
let l:text = getline(l:lnum)
if l:text =~# '^\%( \{3\}\)\=\S.*$'
call add(l:toc, { 'bufnr': bufnr('%'), 'lnum': l:lnum, 'text': l:text })
endif
let l:lnum = nextnonblank(l:lnum + 1)
endwhile
call setloclist(0, l:toc, ' ')
call setloclist(0, [], 'a', { 'title': 'Man TOC' })
" Prepare and set options for the window.
vertical leftabove lopen
vert resize 35
setlocal winfixwidth
setlocal nonumber norelativenumber
" Define mappings.
nnoremap <buffer><silent> l <Enter>zt
nnoremap <buffer><silent> <Enter> <Enter>zt
" Abort if there is nothing to show.
let l:list = getloclist(0)
if empty(l:list)
return v:false
endif
let l:bufnr = l:list[0].bufnr
setlocal modifiable
silent 1,$delete _
call setline(1, map(l:list, 'v:val.text'))
setlocal nomodifiable nomodified
let &syntax = getbufvar(l:bufnr, '&syntax')
let w:qf_toc = l:bufname
" Move the window to the other side.
wincmd x
endfunction
""
" Open man page under the cursor.
"
" nnoremap <buffer><silent> <C-]> :call man#jumptag()<Enter>
""
function! man#jumptag() abort
call man#open_page(v:false, 1, '')
endfunction
""
" Jump to the previous entry in tag stack.
"
" nnoremap <buffer><silent> [g :call man#poptag()<Enter>
""
function! man#poptag() abort
call man#pop_tag()
endfunction
" Disable built-in ftplugin.
let b:did_ftplugin = v:true
" Initialize the manual page.
if !exists('b:man_sect')
call man#init_pager()
endif
" Set common buffer-only settings.
setlocal buftype=nofile bufhidden=hide noswapfile nomodified readonly nomodifiable
setlocal noexpandtab tabstop=8 softtabstop=8 shiftwidth=8
setlocal nonumber norelativenumber
setlocal foldmethod=indent nofoldenable
setlocal colorcolumn=0
setlocal signcolumn=no
" Define mappings.
nnoremap <buffer><silent> O :call man#showtoc()<Enter>
nnoremap <buffer><silent> <C-}> :call man#jumptag()<Enter>
nnoremap <buffer><silent> {g :call man#poptag()<Enter>