I’m using Vim to read man and I’m trying to set up a script in my vimrc that will display NERDTree unless I’m reading from a man page.
I’ve got the following in vimrc:
" This is needed because $MANPATH wasn't set in my environment
let $MANPATH=substitute(system("manpath"),"\n","","")
if (match(expand("%:p:h"),$MANPATH) == -1)
echo ("manpath is: ".$MANPATH)
echo ("path is: ".expand("%:p:h"))
echo ("match: ".match(expand("%:p:h"),$MANPATH))
" Load NERDTree here
endif
When I run vim normally, it works as expected:
andrey@Andrey-P:~$ vim file.txt
manpath is: /usr/local/man:/usr/local/share/man:/usr/share/man
path is: /home/andrey
match: -1
However, opening a man page returns this:
andrey@Andrey-P:~$ man vim
manpath is: /usr/local/man:/usr/local/share/man:/usr/share/man
path is: /usr/share/man
match: -1
One would expect this to be a fairly straightforward match to make, but it doesn’t seem to work. Can anyone help?
It looks like you’ve got the arguments to
match()the wrong way around. The first argument should be the expression to be searched ($MANPATHin your case) and the second argument should be search pattern.See
:help match()for a full description of the function.