visual-studio-codelinux-kernelcygwin

Integrating Visual Studio Code into Cygwin


I was wondering if there was a way to have Visual Studio Code open a file when accessed by Cygwin. For instance, when using an alias to change directories and open a Verilog file, have that file be opened within Visual Studio Code instead. I have very limited experience in Linux, and it looks like Visual Studio Code is easier to navigate/edit scripts, though that could be wrong.


Solution

  • One way to open a windows command (that is not in the path) from the cygwin terminal is to create an shell alias to start VSCode or Visual Studio with a filename from the cygwin terminal. Add a line to your .bashrc like:

    alias vscode=<path to vscode>
    

    Find <path to vscode> by right clicking on the link you use to open VSCode or Visual Studio using the desktop or start menu, and select "More -> Open file location". This will open an explorer window with a shortcut highlighted. Right click on it, and select "Properties". In properties click on the "Open file location" button. In the resulting explorer windows, use shift-right click on the highlighted file and select "Copy as path".

    Back in cygwin, enter

    cygpath -wa <paste>
    

    (In the cygwin terminal, use "Right click -> Paste" or shift-ctrl-C to paste). Then use line editing to change the double quotes to single quotes and run the command. This shows you the string to use as <path to vscode> in the alias command. You must restart the cygwin terminal for the alias to be available.

    To use this alias, enter e.g.

    vscode <filename.ext>
    

    to open the file is VS Code or Visual Studio. I use similar alias to open an explorer window, or my browser with an html file, or to open a file in Notepad++.