Say I have a project in a directory called project-foo
. This project has multiple files and subdirectories.
In vim/neovim, my pwd
is project-foo
and my open buffer is project-foo/src/test/bar.js
.
How can I open this file in VSCode in the project context (not individual file by itself)?
Another way to ask: is there a way to get VSCode to open with the project context and specifically focus a particular file?
Expanding on this, let's say I want to open the specific file project-foo/src/test/bar.js
. I could type `code project-foo/src/test/bar.js'. But that opens VSCode with only awareness of that specific file unless VSCode already has this project open.
I essentially want the equivalent of:
> cd project-foo
> code .
(in VSCode) ⌘ p src/test/bar.js <enter>
but in command line form.
CodePudding user response:
Given it'll open the file in the context of the project if VSCode is already open to the project, you can accomplish this (and handle when VSCode isn't launched) with the following semi-hack:
> cd project-off
> code . && code ./src/test/bar.js
In vim/neovim, you could add a keymap that executes the following
:!code . && code %
Explanation:
!
will run the proceeding text as a shell command
code .
will open the current project
&& code %
will then execute vscode again but with with the current buffer path (magic %
)