Vim: check if running as a pager

ε祈祈猫儿з 提交于 2019-12-12 03:14:00

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!