Skip to content

Instantly share code, notes, and snippets.

@RichardBronosky
Last active December 21, 2022 12:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RichardBronosky/94024fac52780e03c936589f4c9ab914 to your computer and use it in GitHub Desktop.
Save RichardBronosky/94024fac52780e03c936589f4c9ab914 to your computer and use it in GitHub Desktop.
A vim wrapper that allow you to use it for a pager, man reader, etc.
#!/usr/bin/env bash
set -eu
cache_file="/tmp/pager.cache"
[[ ! -p "$cache_file" ]] && touch "$cache_file" && trap "rm $cache_file" 0
cat > "$cache_file"
vim -R -c "terminal cat $cache_file"
@cakemanny
Copy link

cakemanny commented Mar 22, 2021

vim -R --not-a-term -c "terminal cat $cache_file" -c "only" -

-c "only" to close windows other than the one containing the terminal output
- to silence the Vim: Warning: Input is not from a terminal and moreover, without this, the terminal gets rather messed up!
--not-a-term to silence the Vim: Reading from stdin...

or even better:

vim -R -c "call term_start('cat $cache_file', {'hidden': 1, 'term_finish': 'open', 'term_opencmd': 'buffer %d'})" -

this feels much nicer when used as MANPAGER
the former command leaves us at the bottom of the man page, this one puts us at the top, just like less.

Thanks for the starting point by the way!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment