问题
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.
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/39470081/vim-check-if-running-as-a-pager