When executing a vim command, such as the following:

:w!<CR>:!cd %:p:h

What is the effect after the command is finished? Is the new cwd the directory that I've cd'ed into? Or does that only last for the duration of the command?

  • 2
    Why would you want to cd to a different directory running in an external subprocess from Vim? That does not seem to make any sense. Rather use :cd or :lcd or :tcd or :set autochdir Jan 21 at 7:47
  • 3
    Related: Why does !cd not change the directory Note that in your example the directory is not (directly) changed by a "Vim command" it's changed by a shell command in a different process (child).
    – B Layer
    Jan 21 at 9:17