I am trying to give visual-studio-code a go to see if it would be a good code editor for me. So I have it installed. However, I also already had/have Sublime Text 3 installed. I cannot for the life of me figure out how to get vscode to run from the CLI/terminal.

Running:

code README.md

Opens up a README in sublime.

Yet when I do which code => /usr/bin/code => /usr/share/code/bin/code the files in /usr/share/code have license text files for VSCode:

$ head -3 /usr/share/code/resources/app/LICENSE.txt 
MICROSOFT SOFTWARE LICENSE TERMS
MICROSOFT VISUAL STUDIO CODE 
...

What I have tried:

I uninstalled vscode:

sudo apt remove --purge code
sudo apt install code

And yet running code someTextFile.txt (or /usr/bin/code or /usr/share/code/bin/code) still opens sublime instead of vscode.

How can I fix the command to allow me to run vscode to open code files from the CLI?

  • Add the output of type -a code to the post, please – muru May 31 at 12:12
  • Thanks @muru That solves my problem, it is referencing a function still present somewhere: type -a code code is a function code () { command subl "$@" & disown } code is /usr/bin/code Wasn't aware of type -a command, thanks! – Kzqai Jun 1 at 14:19
  • Now I just have to track down where I have that function. – Kzqai Jun 1 at 14:19
  • Try superuser.com/a/229038 – muru Jun 1 at 15:59
  • That's got it, it was a combination of an alias referencing code and a function masking that alias, make this an answer and I'll certainly accept it: run: make -a yourCommandHere to find out where the command is coming from, then to find where it is, if it is a function: shopt -s extdebug;declare -F yourFunctionHere;shopt -u extdebug – Kzqai Jun 2 at 12:14

I was only able to find this due to the comments above for debugging commands. The source of this issue ended up being the following:

I had an alias that looked like this:

alias e="code"

Then later on I had a function that was mapping:

function e() { subl }

Which was overriding the alias. So a search for "code" found the alias that I expected, but since apparently functions get checked first, it was still calling for the function e instead of the alias.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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