Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read man page in split mode #4

Open
oz123 opened this issue Jan 11, 2015 · 4 comments
Open

Read man page in split mode #4

oz123 opened this issue Jan 11, 2015 · 4 comments

Comments

@oz123
Copy link

oz123 commented Jan 11, 2015

Hi,
I find superman really great, especially when doing c programming and needing to read man pages.
I use the plugin from inside vim with for example

:SuperMan printf

I would like to open the man page in a split. Currently it creates a new buffer, and loads in a complete windows.

@jez
Copy link
Owner

jez commented Jan 11, 2015

I'm right there with you. I just haven't found any way to do it that doesn't involve huge hacks.

There's a section from $VIMRUNTIME/ftplugin/man.vim that is of interest here:

  " Use an existing "man" window if it exists, otherwise open a new one.
  if &filetype != "man"
    let thiswin = winnr()
    exe "norm! \<C-W>b"
    if winnr() > 1
      exe "norm! " . thiswin . "\<C-W>w"
      while 1
        if &filetype == "man"
          break
        endif
        exe "norm! \<C-W>w"
        if thiswin == winnr()
          break
        endif
      endwhile
    endif
    if &filetype != "man"
      new
      setl nonu fdc=0
    endif
  endif
  silent exec "edit $HOME/".page.".".sect."~"

It's a little hard to follow, but it basically searches through all windows within the active tab for one with filetype set to "man". If it doesn't find one or if there is only one window in this tab, it uses new to create a horizontal split. If that line were tabnew instead of new, it would open all man pages in a tab instead of a split.

In the plugin right now, I use only to force the split to go away, thus allowing the man page to take up the whole screen.

I'm going to investigate this a little bit further, but I'd love to hear suggestions on how to accomplish this better. It might involve submitting a patch to the upstream man.vim plugin.

@nhooyr
Copy link

nhooyr commented Feb 4, 2016

I redid a lot of the vim man page plugin here to make it better at handling different sections of manpages and only use the edit command to open the page. This allows you to easily do stuff like vsplit|Neoman printf to open in a vertical split. I cleaned up a lot of the code (but it may have bugs, its very alpha). I also added autocomplete for the new command (:Neoman).

I also made it easy to integrate it with the neovim terminal. E.g. if you have a terminal buffer open in a window in neovim and you type man printf instead of opening a new neovim instance, it tells the existing neovim to open that man page.

This is the zsh function I use and you will need https://github.com/mhinz/neovim-remote

nman() {
    if [[ "$@" == "" ]]; then
        print "What manual page do you want?"
        return
    fi
    /usr/bin/man "$@" > /dev/null 2>&1
    if [[ "$?" != "0" ]]; then
        print "No manual entry for $*"
        return
    fi
    if [ -z $NVIM_LISTEN_ADDRESS ]; then
        /usr/bin/env nvim -c "Neoman $*"
    else
        nvr --remote-send "<c-n>" -c "Neoman $*"
    fi
}

Its again a work in progress and I'm changing a lot, still have to add the credits to this plugin which gave me the idea. None of this extra code should have any conflicts with the original man. Everything is done under neoman (e.g. filetype is neoman)

@nhooyr
Copy link

nhooyr commented Feb 11, 2016

I just gave neoman.vim a massive update. Its pretty good now.

@jez
Copy link
Owner

jez commented Feb 14, 2016

Huh, that's very interesting; i'll have to give it a look. I haven't really been able to get into NeoVim's :term command (back when I first saw it the keybindings to navigate buffers were really clunky and I didn't bother changing them).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants