While using Neovim, I love :term very much.

Most of the time, I do the following steps:

  1. vsplit to open a vertical window.
  2. :term in the new window to enter terminal.
  3. $ cd CURRENT_PATH in the shell.

I was wondering if maybe I could combine them all in one vim command?


In Vim, the | character is used as a command separator, making it equivalent to the semicolon in the Unix shell. Furthermore, the full syntax to the :term command is as follows:

:te[rminal][!] {cmd}

Therefore, I believe the following command should do the trick:

:let CP=expand('%:p:h') | vsplit | exec ':term "cd ' .CP .'"'

I do not have Neovim installed, however, so am unable to test this command at the moment.

  • :vsplit | term works, but :vsplit | term "cd CURRENT_PATH" doesn't. I know that :echo expand('%:p') will show the current path, I want to know how to make it as the path in the new termianl.
    – hellotli
    Feb 28 '17 at 7:03
  • Maybe that's because I'm using fish shell, I will tried to figure it out. Thanks.
    – hellotli
    Feb 28 '17 at 7:05
  • 1
    @liweijian I was erroneously treating CURRENT_PATH as a sort of dummy variable. I guess I didn't fully understand what we were trying to accomplish. I have updated my answer. I think you might have better luck with the new command I have proposed (though it now feels a bit hacky). Feb 28 '17 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.