2
export MANPAGER="nvim +set\ filetype=man -"

I have this under my shell configuration, I've been using neovim as my man pager and one thing I love most is its table of contents functionality, pressing gO or by calling man#show_toc() function. Currently when I open a man page with man fzf command for example, pressing gO would bring location list at the bottom of the window like this

and the thing I want to see is this,

but it should be open automatically every time when I run man command.

call man#show_toc() | quit
vertical topleft lopen
vertical resize 40
setlocal nonumber norelativenumber
wincmd p

I could do by entering these commands by hand or putting them in a file named ftplugin/man.vim but still it doesn't feel right, such like syntax highlighting doesn't work. Is there any better way to achieve this?

1 Answer 1

2

You could try to install an autocmd listening to FileType qf, which would check whether the title of the location window is Man TOC, and which would reposition the latter on the far left of the screen (+ resize it):

augroup reposition_man_toc
    au!
    au FileType qf  call s:reposition_man_toc()
augroup END

fu! s:reposition_man_toc() abort
    let title = get(getloclist(0, {'title':1}), 'title', '')
    if title isnot# 'Man TOC'
        return
    endif
    wincmd H
    vert resize 40
endfu

If you want the location window to be automatically opened, as you suggested, you could also try to add a 2nd autocmd:

au FileType man call man#show_toc()

Which would give:

augroup reposition_man_toc
    au!
    au FileType man  call man#show_toc()
    au FileType qf  call s:reposition_man_toc()
augroup END

fu! s:reposition_man_toc() abort
    let title = get(getloclist(0, {'title':1}), 'title', '')
    if title isnot# 'Man TOC'
        return
    endif
    wincmd H
    vert resize 40
endfu

Or maybe you could install a single autocmd:

augroup open_toc
    au!
    au FileType  man  call s:open_toc()
augroup END

fu! s:open_toc() abort
    call man#show_toc()
    let title = get(getloclist(0, {'title':1}), 'title', '')
    if title isnot# 'Man TOC'
        return
    endif
    wincmd H
    vert resize 40
endfu

As rightly pointed out by Christian Brabandt, you could simplify the code by using the window-local variable w:quickfix_title, and eliminate the call to getloclist(). It would give:

augroup open_toc
    au!
    au FileType  man  call s:open_toc()
augroup END

fu! s:open_toc() abort
    call man#show_toc()
    if w:quickfix_title isnot# 'Man TOC'
        return
    endif
    wincmd H
    vert resize 40
endfu
4
  • Thanks, it works quite good but I said it should be automatic process, can you add au FileType man call man#show_toc() too, so I can accept this answer. Feb 23, 2018 at 17:49
  • Thank you so much spending your time for your answer! I'm grateful. Feb 23, 2018 at 19:03
  • 1
    Since you are using au FileType qf call s:reposition_man_toc() you could simply check the window title variable w:quickfix_title instead of the getloclist() call Feb 23, 2018 at 20:26
  • @ChristianBrabandt Honestly I don't even check with getloclist(), because it turns out to be useless, we are calling function man#show_toc(), it will open Man TOC list without a doubt. I use this version now. gist.github.com/kutsan/f1a4edb737e6121d85be7407901b7d58 Feb 24, 2018 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.