Viewing man pages in vim
up vote
5
down vote
favorite
I wrote a function in bash to see manpages
in vim
viman () { man "$@" | vim -R +":set ft=man" - ; }
This works fine, the only problem occurs if I pass a manpage
to it which doesn't exist. It prints that the manpage
doesn't exist but still opens vim
with an empty buffer.
So, I changed the function to check the error code ( which is 16
here ) and exit if the manpage
doesn't exist. The modefied function looks somewhat like this -
viman () { man "$@" | [[ $? == 16 ]] && exit 1 | vim -R +":set ft=man" - ; }
But, now it doesn't do anything!!
I just want to quit the program if the manpage
doesn't exist otherwise open the manpage
with vim
bash vim man function
add a comment |
up vote
5
down vote
favorite
I wrote a function in bash to see manpages
in vim
viman () { man "$@" | vim -R +":set ft=man" - ; }
This works fine, the only problem occurs if I pass a manpage
to it which doesn't exist. It prints that the manpage
doesn't exist but still opens vim
with an empty buffer.
So, I changed the function to check the error code ( which is 16
here ) and exit if the manpage
doesn't exist. The modefied function looks somewhat like this -
viman () { man "$@" | [[ $? == 16 ]] && exit 1 | vim -R +":set ft=man" - ; }
But, now it doesn't do anything!!
I just want to quit the program if the manpage
doesn't exist otherwise open the manpage
with vim
bash vim man function
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I wrote a function in bash to see manpages
in vim
viman () { man "$@" | vim -R +":set ft=man" - ; }
This works fine, the only problem occurs if I pass a manpage
to it which doesn't exist. It prints that the manpage
doesn't exist but still opens vim
with an empty buffer.
So, I changed the function to check the error code ( which is 16
here ) and exit if the manpage
doesn't exist. The modefied function looks somewhat like this -
viman () { man "$@" | [[ $? == 16 ]] && exit 1 | vim -R +":set ft=man" - ; }
But, now it doesn't do anything!!
I just want to quit the program if the manpage
doesn't exist otherwise open the manpage
with vim
bash vim man function
I wrote a function in bash to see manpages
in vim
viman () { man "$@" | vim -R +":set ft=man" - ; }
This works fine, the only problem occurs if I pass a manpage
to it which doesn't exist. It prints that the manpage
doesn't exist but still opens vim
with an empty buffer.
So, I changed the function to check the error code ( which is 16
here ) and exit if the manpage
doesn't exist. The modefied function looks somewhat like this -
viman () { man "$@" | [[ $? == 16 ]] && exit 1 | vim -R +":set ft=man" - ; }
But, now it doesn't do anything!!
I just want to quit the program if the manpage
doesn't exist otherwise open the manpage
with vim
bash vim man function
bash vim man function
edited 5 hours ago
Jeff Schaller
37.5k1052121
37.5k1052121
asked 5 hours ago
Ritajit Kundu
315
315
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
4
down vote
accepted
Try this: capture the man output, and if successful launch vim
viman () { text=$(man "$@") && echo "$text" | vim -R +":set ft=man" - ; }
Capturing the output in a text is a simple and brilliant idea. Putting all things together theviman
function is ready -viman () { text=$(man "$@") && echo "$text" | vim -R +":set ft=man nomod nonu noma nolist colorcolumn=" - ; }
– Ritajit Kundu
5 hours ago
add a comment |
up vote
3
down vote
I like the idea of checking the man
return code; you can't pipe to the test, though. You could just run man
twice:
viman () { man "$@" >/dev/null 2>&1 && man "$@" | vim -R +":set ft=man" - ; }
This runs man ... | vim ...
only if the first invocation of man
was successful.
add a comment |
up vote
0
down vote
Based on this answer this starts vim and exits if there's nothing in the buffer. The disadvantage is that it starts vim
so the screen "flashes". It also doesn't set an exit code when a man
page isn't found.
viman () { vim -R +':set ft=man|exe !search(".")?"quit!":""' <(man "$@" 2>/dev/null); }
This is an improvement on Jeff Schaller's answer in that it doesn't load the the man
page twice when it exists. It also doesn't load vim
unnecessarily like my previous example. And it does set an exit code when there's no man
page.
viman () { man -f "$@" >/dev/null 2>&1 && vim -R +":set ft=man" <(man "$@"); }
Both examples use Bash process substitution in order to avoid the "Vim: Reading from stdin..." message.
Neither loads the page into a variable.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
Try this: capture the man output, and if successful launch vim
viman () { text=$(man "$@") && echo "$text" | vim -R +":set ft=man" - ; }
Capturing the output in a text is a simple and brilliant idea. Putting all things together theviman
function is ready -viman () { text=$(man "$@") && echo "$text" | vim -R +":set ft=man nomod nonu noma nolist colorcolumn=" - ; }
– Ritajit Kundu
5 hours ago
add a comment |
up vote
4
down vote
accepted
Try this: capture the man output, and if successful launch vim
viman () { text=$(man "$@") && echo "$text" | vim -R +":set ft=man" - ; }
Capturing the output in a text is a simple and brilliant idea. Putting all things together theviman
function is ready -viman () { text=$(man "$@") && echo "$text" | vim -R +":set ft=man nomod nonu noma nolist colorcolumn=" - ; }
– Ritajit Kundu
5 hours ago
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
Try this: capture the man output, and if successful launch vim
viman () { text=$(man "$@") && echo "$text" | vim -R +":set ft=man" - ; }
Try this: capture the man output, and if successful launch vim
viman () { text=$(man "$@") && echo "$text" | vim -R +":set ft=man" - ; }
answered 5 hours ago
glenn jackman
49.9k569106
49.9k569106
Capturing the output in a text is a simple and brilliant idea. Putting all things together theviman
function is ready -viman () { text=$(man "$@") && echo "$text" | vim -R +":set ft=man nomod nonu noma nolist colorcolumn=" - ; }
– Ritajit Kundu
5 hours ago
add a comment |
Capturing the output in a text is a simple and brilliant idea. Putting all things together theviman
function is ready -viman () { text=$(man "$@") && echo "$text" | vim -R +":set ft=man nomod nonu noma nolist colorcolumn=" - ; }
– Ritajit Kundu
5 hours ago
Capturing the output in a text is a simple and brilliant idea. Putting all things together the
viman
function is ready - viman () { text=$(man "$@") && echo "$text" | vim -R +":set ft=man nomod nonu noma nolist colorcolumn=" - ; }
– Ritajit Kundu
5 hours ago
Capturing the output in a text is a simple and brilliant idea. Putting all things together the
viman
function is ready - viman () { text=$(man "$@") && echo "$text" | vim -R +":set ft=man nomod nonu noma nolist colorcolumn=" - ; }
– Ritajit Kundu
5 hours ago
add a comment |
up vote
3
down vote
I like the idea of checking the man
return code; you can't pipe to the test, though. You could just run man
twice:
viman () { man "$@" >/dev/null 2>&1 && man "$@" | vim -R +":set ft=man" - ; }
This runs man ... | vim ...
only if the first invocation of man
was successful.
add a comment |
up vote
3
down vote
I like the idea of checking the man
return code; you can't pipe to the test, though. You could just run man
twice:
viman () { man "$@" >/dev/null 2>&1 && man "$@" | vim -R +":set ft=man" - ; }
This runs man ... | vim ...
only if the first invocation of man
was successful.
add a comment |
up vote
3
down vote
up vote
3
down vote
I like the idea of checking the man
return code; you can't pipe to the test, though. You could just run man
twice:
viman () { man "$@" >/dev/null 2>&1 && man "$@" | vim -R +":set ft=man" - ; }
This runs man ... | vim ...
only if the first invocation of man
was successful.
I like the idea of checking the man
return code; you can't pipe to the test, though. You could just run man
twice:
viman () { man "$@" >/dev/null 2>&1 && man "$@" | vim -R +":set ft=man" - ; }
This runs man ... | vim ...
only if the first invocation of man
was successful.
edited 3 hours ago
answered 5 hours ago
Jeff Schaller
37.5k1052121
37.5k1052121
add a comment |
add a comment |
up vote
0
down vote
Based on this answer this starts vim and exits if there's nothing in the buffer. The disadvantage is that it starts vim
so the screen "flashes". It also doesn't set an exit code when a man
page isn't found.
viman () { vim -R +':set ft=man|exe !search(".")?"quit!":""' <(man "$@" 2>/dev/null); }
This is an improvement on Jeff Schaller's answer in that it doesn't load the the man
page twice when it exists. It also doesn't load vim
unnecessarily like my previous example. And it does set an exit code when there's no man
page.
viman () { man -f "$@" >/dev/null 2>&1 && vim -R +":set ft=man" <(man "$@"); }
Both examples use Bash process substitution in order to avoid the "Vim: Reading from stdin..." message.
Neither loads the page into a variable.
add a comment |
up vote
0
down vote
Based on this answer this starts vim and exits if there's nothing in the buffer. The disadvantage is that it starts vim
so the screen "flashes". It also doesn't set an exit code when a man
page isn't found.
viman () { vim -R +':set ft=man|exe !search(".")?"quit!":""' <(man "$@" 2>/dev/null); }
This is an improvement on Jeff Schaller's answer in that it doesn't load the the man
page twice when it exists. It also doesn't load vim
unnecessarily like my previous example. And it does set an exit code when there's no man
page.
viman () { man -f "$@" >/dev/null 2>&1 && vim -R +":set ft=man" <(man "$@"); }
Both examples use Bash process substitution in order to avoid the "Vim: Reading from stdin..." message.
Neither loads the page into a variable.
add a comment |
up vote
0
down vote
up vote
0
down vote
Based on this answer this starts vim and exits if there's nothing in the buffer. The disadvantage is that it starts vim
so the screen "flashes". It also doesn't set an exit code when a man
page isn't found.
viman () { vim -R +':set ft=man|exe !search(".")?"quit!":""' <(man "$@" 2>/dev/null); }
This is an improvement on Jeff Schaller's answer in that it doesn't load the the man
page twice when it exists. It also doesn't load vim
unnecessarily like my previous example. And it does set an exit code when there's no man
page.
viman () { man -f "$@" >/dev/null 2>&1 && vim -R +":set ft=man" <(man "$@"); }
Both examples use Bash process substitution in order to avoid the "Vim: Reading from stdin..." message.
Neither loads the page into a variable.
Based on this answer this starts vim and exits if there's nothing in the buffer. The disadvantage is that it starts vim
so the screen "flashes". It also doesn't set an exit code when a man
page isn't found.
viman () { vim -R +':set ft=man|exe !search(".")?"quit!":""' <(man "$@" 2>/dev/null); }
This is an improvement on Jeff Schaller's answer in that it doesn't load the the man
page twice when it exists. It also doesn't load vim
unnecessarily like my previous example. And it does set an exit code when there's no man
page.
viman () { man -f "$@" >/dev/null 2>&1 && vim -R +":set ft=man" <(man "$@"); }
Both examples use Bash process substitution in order to avoid the "Vim: Reading from stdin..." message.
Neither loads the page into a variable.
answered 27 mins ago
Dennis Williamson
5,33812232
5,33812232
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487415%2fviewing-man-pages-in-vim%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown