1

I searched through Vim's source repository (which includes help doc too) for any references to pager but couldn't find so asking here- Is there a way to see if vim is running as a pager? I'd like to run certain commnands automatically when that happens.

EDIT: By pager, I mean vim reading from stdin when piped as vim -. I use a plugin called AnsiEsc mentioned in another vim related question so would like to load that automatically. I would also like to remap some keybindings.

0fnt
  • 8,211
  • 9
  • 45
  • 62
  • Vim being a text editor, defining what "running as a pager" means and explaining what you do to toward that end should help us help you. – romainl Sep 13 '16 at 12:33
  • Well I meant vim reading from stdin when piped as `vim -`. I use a plugin called AnsiEsc mentioned in another vim related question so would like to load that automatically. I would also like to remap some keybindings. – 0fnt Sep 13 '16 at 12:56
  • 2
    Add that information to your question, please. – romainl Sep 13 '16 at 13:05
  • 2
    Duplicate of http://stackoverflow.com/questions/31548204/vimscript-detect-piped-input/31553281#31553281. I have voted to close. – 0fnt Sep 14 '16 at 04:02
  • Possible duplicate of [vimscript detect piped input](https://stackoverflow.com/questions/31548204/vimscript-detect-piped-input) – gmarmstrong Jun 11 '18 at 13:24

2 Answers2

4

You should be able to register an autocommand on StdinReadPre or Post. e.g.

" .vimrc
aug StdIn
  au! 
  au StdinReadPost * echomsg "In pager mode!"
aug END

I don't see anything else in Vim.

Luc Hermitte
  • 31,979
  • 7
  • 69
  • 83
3

The StdinReadPost (TIL) seems to be perfect for your use case but well, here is a makeshift alternative:

augroup pager
    autocmd!
    autocmd VimEnter * if v:statusmsg =~ 'stdin' | echomsg "is pager" | endif
augroup END
romainl
  • 186,200
  • 21
  • 280
  • 313