jez / vim-superman

Read Unix man pages faster than a speeding bullet!
http://blog.jez.io/2014/12/20/vim-as-a-man-page-viewer/
MIT License
190 stars 20 forks source link

Read man page in split mode #4

Open oz123 opened 9 years ago

oz123 commented 9 years ago

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 commented 9 years ago

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 commented 8 years ago

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 commented 8 years ago

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

jez commented 8 years ago

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