# Using vim as a man page reader

## shm

Vim has much better syntax highlighting support for man pagers than man does, so you can use vim to read manpages. 

Just add 

```
export MANPAGER="col -b | view -c 'set ft=man nomod nolist' -" 
```

to your ~/.bashrc

This tip from http://www.vim.org/tips/tip.php?tip_id=167

----------

## neuronal

great!  :Laughing: 

----------

## yuk159

Yes great, thanks  :Mr. Green: 

----------

## Paidhi

Cool!    :Razz: 

----------

## iwasbiggs

I have no "view" command (only emerge gvim),  replacing it with vim -R works though.

----------

## neuronal

Have you emerged vim?

```
$ qpkg -f /usr/bin/view

app-editors/vim *
```

----------

## cselkirk

here I use a script for calling (rather than an env) ..

```
#!/bin/sh

# vman.sh

if [[ $1 = "-k" ]]; then

    man -k $2

    exit

elif

   [[ $TERM = "screen" ]]; then

    screen man -P "col -b | $VIMRUNTIME/macros/less.sh -c \

      'set ft=man nomod nolist laststatus=0 loadplugins=off' - " $1

    exit

else 

    man -P "col -b | $VIMRUNTIME/macros/less.sh -c \

      'set ft=man nomod nolist laststatus=0 loadplugins=off' - " $1

    exit

fi
```

You could of course alias this to man

----------

## TGL

And now the x11 version, using gvim:

```
#!/bin/bash

args="`echo $* | sed 's:\ :\\\ :g'`"

/usr/bin/man $* -P "col -b \

  | gvim -f -R --noplugin \

         --cmd 'set guioptions-=m guioptions-=T guioptions-=t' \

         -c 'set ft=man nomod nolist laststatus=0 columns=78 titlestring=man\ $args' \

         -c 'so \$VIMRUNTIME/macros/less.vim' - " &> /dev/null &
```

If a real vim user has an idea to extract a better titlestring (the "command(section#)" from the top of the displayed manpage would be perfect), I would be interested.

----------

## axxackall

in (X)Emacs you can have access to man pages at any time just by typing M-x man and it will ask you the name of the man page you want to see, by default suggesting to see the man page for the word that was around the cursor at the moment right before you have typed M-x man.

----------

## TGL

This also looks interresting: http://www.vim.org/scripts/script.php?script_id=489

----------

## cselkirk

 *axxackall wrote:*   

> in (X)Emacs you can have access to man pages at any time just by typing M-x man and it will ask you the name of the man page you want to see, by default suggesting to see the man page for the word that was around the cursor at the moment right before you have typed M-x man.

 

And vim also .. "^K" .. but thats not what this thread is about.

----------

## Kraymer

In general, I like "most" as replacement for less  :Smile: 

----------

## Hydralisk

Here is the python script which I currently use as my pager.

```

#!/usr/bin/env python

import os

import sys

from popen2 import popen2

def main():

   ismanpager = 0

   for arg in sys.argv[1:]:

      if arg == '-m':

         ismanpager = 1

   

   if ismanpager:

      vim_cmd = 'view -c \'set ft=man nomod\' -'

   else:

      vim_cmd = 'view -c \'set nomod\' -'

   

   col_stdout, col_stdin = popen2('col -b')

   for line in sys.stdin:

      col_stdin.write(line)

   try:

      col_stdin.close()

   except IOError:

      pass

   

   vim_stdin = os.popen(vim_cmd, 'w')

   for line in col_stdout:

      vim_stdin.write(line)

   vim_stdin.close()

   col_stdout.close()

if __name__ == '__main__':

   main()

```

Put that in /usr/local/bin/vimpage (or wherever you want, actually), and then put this in your .bashrc:

```

export PAGER="/usr/local/bin/vimpage"

export MANPAGER="/usr/local/bin/vimpage -m"

```

----------

## TGL

 *Hydralisk wrote:*   

> 
> 
> ```
> 
> #!/usr/bin/env python
> ...

 

Isn't this 100% equivalent the original trick?:

```
export PAGER="col -b | view -c 'set nomod' -"

export MANPAGER="col -b | view -c 'set ft=man nomod' -"
```

Any reason to while/for read/write streams instead of piping?

----------

## Wedge_

I seem to be having problems viewing larger manpages. I've tried most of the suggestions in this thread and on the page for the tip on vim.org, and while most of them work fine for smaller pages, larger ones are always cut off. For example, the fvwm manpage is very long, but stops after ~750 lines. Is there something really obvious I'm missing here?

----------

## cselkirk

 *Wedge_ wrote:*   

> I seem to be having problems viewing larger manpages. I've tried most of the suggestions in this thread and on the page for the tip on vim.org, and while most of them work fine for smaller pages, larger ones are always cut off. For example, the fvwm manpage is very long, but stops after ~750 lines. Is there something really obvious I'm missing here?

 

humm .. nothing I can think of, I have the zshall.1 manpage open which is 16064 lines, no cut off.

----------

## TGL

 *Wedge_ wrote:*   

> I seem to be having problems viewing larger manpages.

 

No such issue here neither... Maybe you could try the following to commands:

```
# man -P "col -b" fvwm

# man -P "col -b" fvwm | less

# man -P "col -b" fvwm | vim -

# man -P "col -b" fvwm | vim -c 'set ft=man nomod laststatus=0 loadplugins=off' - 
```

The first one is to test the output filter, the second one the pipe, the third and fouth ones vim without and then with options. If all work as expected, then I really don't understand.

----------

## Wedge_

Every one of those commands does the same thing - fine up till ~750 lines then it just stops  :Confused: 

----------

## TGL

And you're sure it's not your man page that is really truncated? You've tried another one? (asking can't hurt...)

I have no clue why the "col -b" could be in fault here. What if you try this?: 

```
man -P "cat" bash
```

You should also try this:

```
man -d -P "col -b" bash
```

and play with the command displayed at the end (remove the last command to see what happens, etc.).

----------

## Wedge_

If I just do "man fvwm" it works fine. There are several others that do the same thing, all pretty long.  Using "man -P "cat"" works fine.

Edit: Ahaha, thank you TGL - I found the little bugger that was causing trouble. Using the 2nd command you posted, I got this: 

```
cd /usr/share/man && (echo ".pl 1100i"; /bin/gunzip -c '/usr/share/man/man1/bash.1.gz'; echo; echo ".pl \n(nlu+10") | /usr/bin/gtbl | /usr/bin/nroff -Tlatin1 -c -mandoc | col -b
```

-Tlatin1  :Evil or Very Mad:   :Evil or Very Mad:  One quick edit of /etc/man.conf later and everything is working. Thanks   :Wink: 

Edit #2: I changed it to -Tascii if anyone has the same problem.

----------

## Hydralisk

 *TGL wrote:*   

> 
> 
> Isn't this 100% equivalent the original trick?:
> 
> ```
> ...

 

I use it this way because I prefer to have an executable which I can use outside a variable. For example, with my python script, I can just type:

emerge -pev gnome | vimpage

It would be more difficult to do this without my script.

Other than that, there is no difference between piping. Here is a revised version BTW:

```

#!/usr/bin/env python

import os

import sys

def main():

   ismanpager = 0

   for arg in sys.argv[1:]:

      if arg == '-m':

         ismanpager = 1

   

   if ismanpager:

      vim_cmd = 'view -c \'set ft=man nomod\' -'

   else:

      vim_cmd = 'view -c \'set nomod\' -'

   stdin = os.popen('col -b | %s' % vim_cmd, 'w')

   for line in sys.stdin:

      stdin.write(line)

   stdin.close()

if __name__ == '__main__':

   main()

```

----------

## aLEczapKA

there is another cool command to replace less (pager) with vim, use

```
view somefile.txt
```

----------

## TGL

 *Hydralisk wrote:*   

> I use it this way because I prefer to have an executable which I can use outside a variable. 

 

I've understood this, I also uses scripts for this kind of things. That's just the length of the script that surprised me.

----------

## taviso

Dont forget info pages  :Smile: 

```
$ emerge app-vim/info

$ info() { vim "+Info $1" +only; }
```

----------

## etnoy

This tip is too good to be forgotten in the eternal oblivion of Gentoo Forums. Bumping.

Great tip btw!

----------

