Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Using vim as a man page reader
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
shm
Advocate
Advocate


Joined: 09 Dec 2002
Posts: 2380
Location: Atlanta, Universe

PostPosted: Thu Sep 04, 2003 6:30 am    Post subject: Using vim as a man page reader Reply with quote

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

Just add
Code:
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
_________________
what up
Back to top
View user's profile Send private message
neuronal
Apprentice
Apprentice


Joined: 11 Feb 2003
Posts: 174
Location: Alicante/Spain

PostPosted: Thu Sep 04, 2003 7:35 am    Post subject: Reply with quote

great! :lol:
_________________
#!/Enrique/Barbeito/García ...
http://enrique.barbeito.org
Back to top
View user's profile Send private message
yuk159
Veteran
Veteran


Joined: 18 Apr 2003
Posts: 1801
Location: noumea ,nouvelle-caledonie

PostPosted: Thu Sep 04, 2003 4:03 pm    Post subject: Reply with quote

Yes great, thanks :mrgreen:
_________________
The box said: "Requires Windows 98/2000/XP/NT, or better."
So, I installed LINUX!
un blog de plus :)
Back to top
View user's profile Send private message
Paidhi
n00b
n00b


Joined: 11 Jun 2002
Posts: 47
Location: Vienna, Austria

PostPosted: Thu Sep 04, 2003 4:49 pm    Post subject: Reply with quote

Cool! :P
_________________
Unix _IS_ userfriendly. It's just selective about who it's friends are.
Back to top
View user's profile Send private message
iwasbiggs
Apprentice
Apprentice


Joined: 17 Jan 2003
Posts: 203

PostPosted: Sat Sep 06, 2003 12:16 pm    Post subject: Reply with quote

I have no "view" command (only emerge gvim), replacing it with vim -R works though.
_________________
www.ruinedsoft.com
Freeware development.
Back to top
View user's profile Send private message
neuronal
Apprentice
Apprentice


Joined: 11 Feb 2003
Posts: 174
Location: Alicante/Spain

PostPosted: Sat Sep 06, 2003 2:21 pm    Post subject: Reply with quote

Have you emerged vim?

Code:
$ qpkg -f /usr/bin/view
app-editors/vim *

_________________
#!/Enrique/Barbeito/García ...
http://enrique.barbeito.org
Back to top
View user's profile Send private message
cselkirk
Apprentice
Apprentice


Joined: 09 Jun 2003
Posts: 199
Location: NL

PostPosted: Mon Sep 08, 2003 3:47 am    Post subject: Reply with quote

here I use a script for calling (rather than an env) ..
Code:
#!/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
_________________
cn=cselkirk,dc=xs4all,dc=nl
Back to top
View user's profile Send private message
TGL
Bodhisattva
Bodhisattva


Joined: 02 Jun 2002
Posts: 1978
Location: Rennes, France

PostPosted: Mon Sep 08, 2003 10:20 pm    Post subject: Reply with quote

And now the x11 version, using gvim:
Code:
#!/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.
Back to top
View user's profile Send private message
axxackall
l33t
l33t


Joined: 06 Nov 2002
Posts: 651
Location: Toronto, Ontario, 3rd Rock From Sun

PostPosted: Tue Sep 09, 2003 7:07 am    Post subject: Reply with quote

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.
_________________
"Lisp is a programmable programming language." - John Foderaro, CACM, September 1991
Back to top
View user's profile Send private message
TGL
Bodhisattva
Bodhisattva


Joined: 02 Jun 2002
Posts: 1978
Location: Rennes, France

PostPosted: Tue Sep 09, 2003 7:51 am    Post subject: Reply with quote

This also looks interresting: http://www.vim.org/scripts/script.php?script_id=489
Back to top
View user's profile Send private message
cselkirk
Apprentice
Apprentice


Joined: 09 Jun 2003
Posts: 199
Location: NL

PostPosted: Tue Sep 09, 2003 9:49 am    Post subject: Reply with quote

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.
_________________
cn=cselkirk,dc=xs4all,dc=nl
Back to top
View user's profile Send private message
Kraymer
Guru
Guru


Joined: 27 Aug 2003
Posts: 349
Location: Germany

PostPosted: Tue Sep 09, 2003 12:55 pm    Post subject: be the way Reply with quote

In general, I like "most" as replacement for less :-)
Back to top
View user's profile Send private message
Hydralisk
Tux's lil' helper
Tux's lil' helper


Joined: 19 Mar 2003
Posts: 83

PostPosted: Thu Sep 11, 2003 12:17 am    Post subject: Reply with quote

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

Code:

#!/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:

Code:

export PAGER="/usr/local/bin/vimpage"
export MANPAGER="/usr/local/bin/vimpage -m"
Back to top
View user's profile Send private message
TGL
Bodhisattva
Bodhisattva


Joined: 02 Jun 2002
Posts: 1978
Location: Rennes, France

PostPosted: Thu Sep 11, 2003 1:59 am    Post subject: Reply with quote

Hydralisk wrote:
Code:

#!/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()

Isn't this 100% equivalent the original trick?:
Code:
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?
Back to top
View user's profile Send private message
Wedge_
Advocate
Advocate


Joined: 08 Aug 2002
Posts: 3614
Location: Scotland

PostPosted: Thu Sep 11, 2003 8:40 am    Post subject: Reply with quote

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?
_________________
Per Ardua Ad Astra
The Earth is the cradle of the mind, but we cannot live forever in a cradle - Konstantin E. Tsiolkovsky
Gentoo Radeon FAQ
Back to top
View user's profile Send private message
cselkirk
Apprentice
Apprentice


Joined: 09 Jun 2003
Posts: 199
Location: NL

PostPosted: Thu Sep 11, 2003 12:08 pm    Post subject: Reply with quote

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.
_________________
cn=cselkirk,dc=xs4all,dc=nl
Back to top
View user's profile Send private message
TGL
Bodhisattva
Bodhisattva


Joined: 02 Jun 2002
Posts: 1978
Location: Rennes, France

PostPosted: Thu Sep 11, 2003 6:25 pm    Post subject: Reply with quote

Wedge_ wrote:
I seem to be having problems viewing larger manpages.

No such issue here neither... Maybe you could try the following to commands:
Code:
# 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.
Back to top
View user's profile Send private message
Wedge_
Advocate
Advocate


Joined: 08 Aug 2002
Posts: 3614
Location: Scotland

PostPosted: Thu Sep 11, 2003 7:07 pm    Post subject: Reply with quote

Every one of those commands does the same thing - fine up till ~750 lines then it just stops :?
_________________
Per Ardua Ad Astra
The Earth is the cradle of the mind, but we cannot live forever in a cradle - Konstantin E. Tsiolkovsky
Gentoo Radeon FAQ
Back to top
View user's profile Send private message
TGL
Bodhisattva
Bodhisattva


Joined: 02 Jun 2002
Posts: 1978
Location: Rennes, France

PostPosted: Thu Sep 11, 2003 8:16 pm    Post subject: Reply with quote

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?:
Code:
man -P "cat" bash


You should also try this:
Code:
man -d -P "col -b" bash

and play with the command displayed at the end (remove the last command to see what happens, etc.).
Back to top
View user's profile Send private message
Wedge_
Advocate
Advocate


Joined: 08 Aug 2002
Posts: 3614
Location: Scotland

PostPosted: Thu Sep 11, 2003 8:31 pm    Post subject: Reply with quote

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:
Code:
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: :evil: 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.
_________________
Per Ardua Ad Astra
The Earth is the cradle of the mind, but we cannot live forever in a cradle - Konstantin E. Tsiolkovsky
Gentoo Radeon FAQ
Back to top
View user's profile Send private message
Hydralisk
Tux's lil' helper
Tux's lil' helper


Joined: 19 Mar 2003
Posts: 83

PostPosted: Thu Sep 11, 2003 10:42 pm    Post subject: Reply with quote

TGL wrote:

Isn't this 100% equivalent the original trick?:
Code:
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?


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:

Code:

#!/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()
Back to top
View user's profile Send private message
aLEczapKA
Apprentice
Apprentice


Joined: 13 Jun 2003
Posts: 192

PostPosted: Thu Sep 11, 2003 11:31 pm    Post subject: Reply with quote

there is another cool command to replace less (pager) with vim, use
Code:
view somefile.txt

_________________
while true; do eject /dev/cdrom; eject -t /dev/cdrom; done
Back to top
View user's profile Send private message
TGL
Bodhisattva
Bodhisattva


Joined: 02 Jun 2002
Posts: 1978
Location: Rennes, France

PostPosted: Thu Sep 11, 2003 11:32 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
taviso
Retired Dev
Retired Dev


Joined: 15 Apr 2003
Posts: 261
Location: United Kingdom

PostPosted: Fri Sep 12, 2003 6:53 pm    Post subject: Reply with quote

Dont forget info pages :)

Code:
$ emerge app-vim/info
$ info() { vim "+Info $1" +only; }

_________________
--------------------------------------
Gentoo on Alpha, is your penguin 64bit?
--------------------------------------------------------
Back to top
View user's profile Send private message
etnoy
Apprentice
Apprentice


Joined: 29 Aug 2003
Posts: 255
Location: Västerås, Sweden

PostPosted: Sun Jan 30, 2005 9:56 pm    Post subject: Reply with quote

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

Great tip btw!
_________________
The md5sum of the above post is 06280ccd85ef9deb49c336e7945f4b5c

God is dead! - Nietzsche
Nietzsche is dead! -God
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum