Explicitly set starting directory for builtin terminal?

Hi all, so I have started using the built-in terminal-emulator recently, and I ran into an issue that I would like to solve, but I am having some issues finding the right info.

I have a key binding that I use to open the built-in terminal (just putting the run expression here without my custom mapping function involved):

:vsplit | :vertical resize -50 | term<cr>

The issue that I am facing though is that I’ve noticed that my current working directory is not always what I want it to be. In this case, the terminal opens in a different location (where the nvim current working directory is) but the files that I am working in are located way down in subfolders.

Is there a way to open the terminal to a specific directory? I discovered that by doing something like term cd ~ that anything after the term command gets sent to the terminal instance when it opens. But I want to pass a location from nvim to the term and open it there.

Any tips would be greatly appreciated!

You can use :help termopen() for this:

:vnew | call termopen(&shell, #{cwd: '/tmp'})

Thanks for the help! I was not aware there was a termopen call. I think that is definitely what I am looking for, I was having trouble digging through the help because I wasn’t exactly sure what I was looking for.