I am currently trying to tie together a function to do something depending on current file path, triggered whenever I change the current buffer with autocmd BufEnter
In my .vimrc
autocmd BufEnter * call SayLocation()
Further down in my .vimrc
fun SayLocation()
let str = expand("%p:~")
if str =~ "~/dir1"
echo "I am in dir 1!"
elseif str =~ "~/dir2"
echo "I am in dir 2!"
else
echo "I am somewhere else"
endif
endf
However, changing the buffer yields the following error
Line 3:
E33: No previous substitute regular expression
Line 7:
E33: No previous substitute regular expression
I am somewhere else
It seems I am running the substring comparator =~ wrong. Any clue?