How to open a file from terminal in a tmux session in Visual Studio Code - visual-studio-code

One can open a file from the integrated terminal in Visual Studio Code via:
code -r something.dat
Unfortunately, this does not work for me when I work in the terminal within a tmux-session. The error I get is:
-bash: code: command not found
I googled the error and it seems I have to include vscode on my Path variable (example: similar problem).
I'm now confused on what to do as it works from the normal integrated terminal but doesn't work in the tmux "environment".
Do you have any ideas?

Probably you first started the tmux server from a terminal without this in PATH and you are not adding it in any of the shell startup files that the shell uses when started from tmux (remember tmux starts login shells by default).

Related

I have to "source ~/.zshrc" everytime I open a new terminal only in vscode

Currently have to manually write source ./zshrc to get my zsh plugins to work within the vscode terminal window, however I dont have this issue if I open a zsh shell outside of vscode. I am using Debian on wsl2.
In terminal I get proper syntax example (due to a plugin)
However in vscode I dont unless i run source ./zshrc
As seen here:

Looking for help on setting up wsl in vscode terminal

If I'm in my terminal and open a file with the code command, vscode will launch and the terminal inside code will show my full zsh setup that I have configured in hyper terminal. But if I open up code through windows, and select wsl as my default shell, it's pretty much useless. Anything I try, like sudo, git, apt, etc will return a command not found message.
So if I want to commit any changes in the terminal inside code then I have to use the git bash shell. Is it possible to get my zsh working without first launching from my terminal emulator so I'm using wsl instead of git bash?
running wslconfig.exe /list in powershell showed me that WSL was set to docker as the default shell, so then running wslconfig.exe /setdefault "Ubuntu" in powershell fixed my problem.

how to stop VSCode terminal to open a new cmd window in each command?

On window 10 with vscode -v 1.51.1 terminal with cmd.
After writing the command and hitting the enter key... a new window is open and close...
so, if I'm trying to check --version the window is already close and i can't see results..
or if i having an error - i cant see it if the window is close... so for now: i use print screen..
how can i get the process output run on the same window... on the VSCode terminal?
If am understanding your question you can try
code -v
OMG
Turn off ConPTY integration in the
File->Preferences->Settings->conPTY->Uncheck it
Integrated terminal in visual studio code is opening externally and not internally

Visual Studio Code - Where is the terminal history saved?

I noticed that the command history is saved when using Visual Studio Code. Using the arrow up and down keys, I can toggle through previously issued commands in the integrated terminal.
Where is the terminal history saved on the drive? Is it possible to open a file in notepad (or notepad++) and investigate the complete history, delete it?
I'm using Windows 10, and I have concluded that deleting the folders C:\Users\john\.vscode and C:\Users\john\AppData\Roaming\Code will not delete the terminal history for a particular project.
VSCode terminal use external shell. For linux the default shell is bash, I am not so sure about window, but I guess the default shell for window is powershell.
If your terminal shell is indeed powershell, this should help you locate the log file.
On Linux & MacOS, type the following command to display the path of the history file:
echo $HISTFILE
The history file may be different between VSCode and your regular terminal.
So you should type this command within the integrated terminal.
On Ubuntu you can see your history using this command:
vi ~/.bash_history

How to open a file from the integrated terminal in Visual Studio Code?

Is there a way of opening a file from the terminal in Visual Studio Code that opens in the same vscode instance that runs the terminal? Similar to c9 tool in Cloud9.
I'm aware of the code tool, but when you run code something.php from the integrated terminal it opens a new vscode instance, which is not what I want...
You can use -r or --reuse-window command line option.
code -r something.php
just
code file_name
I tried it on Win10 and on Linux (Ubuntu)
I don't know what operating system you're using, but on MacOS you can just say open filename.ext in the integrated terminal, and it will open a new tab in the same VSCode instance, ready for you to edit.
If you are having command not found: code in macOS, use a full path to it.
/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code -r [filename]
Open Visual Studio Code
Press CMD + SHIFT + P (this opens "Command Palette")
Type shell command
Select “Install code command in path”
Navigate to any project from the terminal, and type code .
If it didn't work, select “Uninstall code command from path” first, then reinstall it again.
I use code -r . to open the current directory in the main window.
You can use the code command from the CLI to open a file, but if you want it to open in the existing window, either use code -r <file> as mentioned in other answers (which does work for me on Ubuntu Linux), or, if -r does not work (under WSL?), make sure window.openFilesInNewWindow is either off or default in settings.json or the in VS Code settings UI, then use code <file>.
Many things can be found in open --help
A work around that worked for me on MacOS is:
open -a 'Visual Studio Code.app' something.php
in the version 1.31.0 that I have installed, on Windows 7, the only way I found to do this is to e.g. change the file associations in system so that .cproj and .cs files are opened by Visual Studio Code by default, and type "filename.cs" in Terminal to open file by that name in the same window... -r option is not working for the first call (opens a new window), but with each subsequent call that same window is correctly reused. ok can't get to open whole directories this way - it's a bit shoddy anyway. probably it would be more convenient to use an outside shell and work with "-r" option
VSCode 1.64 (Jan. 2022) comes with a new command:
Keyboard Navigable Links
Previously, link navigation in the terminal required the use of a mouse.
Now, links can be opened using only the keyboard via the following commands:
Terminal: Open Detected Link... to view all links (web, file, word)
Terminal: Open Last Web Link... ex: https://github.com/microsoft/vscode
Terminal: Open Last File Link... ex: /Users/user/repo/file.txt
Check if the last command Terminal: Open Last File Link... would help in your case.
See also "Terminal shell integration"