I edit file
/home/me/projects/myproj/src/util.c And want to start terminal at
/home/me/projects/myproj/src. Vim version > 8 so I can run
:terminal but it always starts at folder in which I've opened vim. Which is
/home/me/projects/myproj. How can I do this?
:cd changes the current directory for all the windows while
:lcd changes the current directory for the current window.
You can change the current directory to the directory containing the current file with:
And you can use
set autochdir in your
.vimrc to change the current working directory whenever you open a file, switch buffers, delete a buffer or open/close a window. It will change to the directory containing the file which was opened or selected. (see
Also note that the doc mentions that
autochdir may break some plugin and this wikia page suggests the following autocommand to replace this setting:
autocmd BufEnter * silent! lcd %:p:h