Vim Tips Wiki
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
FANDOM
Fan Central
BETA
Games
Anime
Movies
TV
Video
Wikis
Explore Wikis
Community Central
Start a Wiki
Don't have an account?
Register
Sign In
Sign In
Register
Vim Tips Wiki
1,649
pages
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
Editing
Open a window with the man page for the word under the cursor
Back to page
Edit
Edit source
View history
Talk (0)
Edit Page
Open a window with the man page for the word under the cursor
We recommend that you
log in
before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your
Watchlist
.
Creating an account
is quick and free.
The edit appears to have already been undone.
Anti-spam check. Do
not
fill this in!
{{TipImported |id=485 |previous=484 |next=488 |created=2003 |complexity=intermediate |author=munk |version=6.0 |rating=15/8 |category1= |category2= }} This short function opens a new window and reads in the Unix man page for the word under the cursor. To use it add the following to your [[vimrc]]: <pre> fun! ReadMan() " Assign current word under cursor to a script variable: let s:man_word = expand('<cword>') " Open a new window: :exe ":wincmd n" " Read in the manpage for man_word (col -b is for formatting): :exe ":r!man " . s:man_word . " | col -b" " Goto first line... :exe ":goto" " and delete it: :exe ":delete" endfun " Map the K key to the ReadMan function: map K :call ReadMan()<CR> </pre> ==Open a Page From a Particular Section in a New Terminal== You might like to be able to hit a key to launch a man page from a certain man section for the word under the cursor: <pre> command -nargs=0 -range ManInGnomeTerm !gnome-terminal --execute bash -i -c 'man $(if [ $(( <line2> - <line1> + 1 )) -ne 1 ]; then echo $(( <line2> - <line1> + 1 )); fi) <cword> || (echo "man lookup failed" 1>&2 && read)' nnoremap <silent> K :ManInGnomeTerm<CR><CR> </pre> This will look up the word under the cursor in a new gnome-terminal. If you press a number key first, it looks only in that manual section (unless the number is 1, in which case you don't need it anyway...). There is one small bug when you try to look in a particular section while near the end of the file, as this results in an Invalid Range error. Just add a few blank lines at the bottom to work around this issue. This approach is perhaps most graceful if you are also [[using vim as a syntax-highlighting pager]] and/or [[using vim as a man-page viewer under Unix]]. ==References== *{{help|windows}} *{{help|:wincmd}} The col command may differ on your version of Unix, see col(1) for details. ==Comments== Addendum: "AFTER THIS: " and delete it: :exe ":delete" " ADD THIS!: " finally set file type to 'man': :exe ":set filetype=man" Which formats the page for man type (make sure to 'setenv TERM xterm' first or similar to see the pwetty colours :) ---- Note that if you're using a recent version of groff, you may have to disable SGR (Ansi escape sequences) in order to view man pages within vim. If you see a whole lot of garbage on the screen, try adding to your .vimrc the line: let $GROFF_NO_SGR=1 ---- Also take a look at ":e $VIMRUNTIME/ftplugin/man.vim". ---- I'd rather put in my ~/.vimrc: source $VIMRUNTIME/ftplugin/man.vim nnoremap K :Man <C-R><C-W><CR> ---- I had the problem that it would open the new window, but loaded the man page itself into the old window. Changing: :exe ":wincmd n" to :exe ":new" fixed it for me. ---- Of course, you could use {{script|id=489}} to do this, too. In addition, one gets :Man topic as well as the use of K to look up the word under the cursor. ---- This also works: source $VIMRUNTIME/ftplugin/man.vim nmap K :Man <cword><CR> ----
Summary:
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Help
(
view source
)
Template:Navigation
(
view source
)
Template:Script
(
view source
)
Template:TipImported
(
view source
)
Follow on IG
TikTok
Join Fan Lab