0

I'm trying to make autocommands that will run only when the buffer is a man page (:Man) but I can't get the right pattern as i'm not too familiar with regexp and globs. here's what i've tried so far:

autocmd! BufEnter *man://* call Myfunc()
autocmd! BufEnter [^man://]* call Myfunc()

but nothing seems to work. any alternatives are okay too

0

From what I have tested this works:

function! Test()
    echom "entering man buffer " . expand('%')
endfunction

autocmd! BufEnter man://* call Test()
  • odd.. I tried it in vim8.1 and nvim0.3 by vim --noplugin -u test.vim but It seems not working.. any idea? – John Fred Fadrigalan Mar 12 at 11:29
  • It only works when I open the man page manually through new man://test(1) but not using the :Man test command. – John Fred Fadrigalan Mar 12 at 12:23
  • Actually it there is something weird: when I do my firt :Man ls the autocommand doesn't work but if I use :Man again it works. I would say that maybe :Man sets the filename after the BufEnter event is triggered. Depending on what you want to do maybe you can use another autocommand event. – statox Mar 12 at 12:43
0

It's probably better to use a FileType buffer. The problem with BufEnter is that the buffer may not yet be fully set up when it's run; I also don't think it's run for new buffers.

I'm also not entirely sure if I follow where you go the man:// pattern from? I don't see that in the source? And using bufname('') gives me /home/martin/ls.~, not man://...?

At any rate, something like this should work as you expect:

autocmd! FileType man call Myfunc()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.