30

In windows, we have an option: adding "Open with code" action to context menu, this allows us to open any file or folder with VS Code.

Is there any way to add this feature in Ubuntu?

Pablo Bianchi
  • 17,371

7 Answers7

57

Run

wget -qO- https://raw.githubusercontent.com/harry-cpp/code-nautilus/master/install.sh | bash

Just run this in your terminal, and it will add open with VS Code in context menu for Ubuntu 18.04 LTS.

Edit: Works as well for Ubuntu 20.04 LTS, 20.10 and 22.04 LTS.

Source: harry-cpp's GitHub Repository

Pablo Bianchi
  • 17,371
8

What you need to do is install Nautilus Actions

sudo apt install nautilus-actions

and add new action :

Path: code Parameters: %B

command

in menu

NOTE ❗ ❗ Modern version of Nautilus Actions (nautilus-actions package in trusty (14.04 LTS), xenial (16.04 LTS), artful (17.10)) are named as FileManager Actions (filemanager-actions package, it is not yet packaged in Debian and Ubuntu - see at repology.org).

sudo add-apt-repository ppa:daniel-marynicz/filemanager-actions

sudo apt-get install filemanager-actions-nautilus-extension 

NOTE 2 As of Ubuntu 19.04, the package is filemanager-actions.

sudo apt-get install filemanager-actions

orginal post askubuntu.com/a/1031746/843203

Leone
  • 81
5

If you're on 20.10 and you're running this script:

wget -qO- https://raw.githubusercontent.com/cra0zy/code-nautilus/master/install.sh | bash`

You'll need to install python3-nautilus because python-nautilus isn't in non-LTS versions of Ubuntu.

Simply install the python3 version of python-nautilus

sudo apt install python3-nautilus

Then restart nautilus (this will close all nautilus folders)

nautilus -q && nautilus &

And it should work.

2

I was able to find this vscode extension for nautilus written by Crazy0 that lets you do this.

The steps can be found in that github gist, which are:

  1. Go to the gist.

  2. And do the following (also found in the head section of that gist):

    • Place me in ~/.local/share/nautilus-python/extensions/, restrart Nautilus, and enjoy :)
    • mkdir -p ~/.local/share/nautilus-python/extensions && cp -f VSCodeExtension.py ~/.local/share/nautilus-python/extensions/VSCodeExtension.py && nautilus -q

Just tested on Ubuntu Bionic and it works great.


Update

The repo for Cra0zy has been archived and these are replacements:

  1. harry-cpp

    • Steps:
      • Install: wget -qO- https://raw.githubusercontent.com/harry-cpp/code-nautilus/master/install.sh | bash
      • Uninstall: rm -f ~/.local/share/nautilus-python/extensions/code-nautilus.py
  2. shaoormunir Fork of repo in 1 above.

    • Steps:
      • Install: wget -qO- https://raw.githubusercontent.com/shaoormunir/code-nautilus/master/install.sh | bash
      • Uninstall: rm -f ~/.local/share/nautilus-python/extensions/code-nautilus.py
George Udosen
  • 37,534
2

1.Create a file ~/.local/share/nautilus/scripts/open-in-code.sh with this content:

#!/bin/bash
if [ -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ]; then
    set $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
    if [ $# -eq 1 ]; then
        destination="$1"
    else
        zenity --error --title="Error - Open in Visual Studio Code" \
        --text="You can only select one file/directory."
        exit 1
    fi
else
    destination="`echo "$NAUTILUS_SCRIPT_CURRENT_URI" | sed 's/^file:\/\///'`"
fi

# It's only possible to go to local directories
if [ -n "`echo "$destination" | grep '^[a-zA-Z0-9]\+:'`" ]; then
    zenity --error --title="Error - Open in Visual Studio Code" \
    --text="Only local directories can be used."
    exit 1
fi

exec code "$destination"

2.Add execution permission to the file:

 $ chmod +x ~/.local/share/nautilus/scripts/open-in-code.sh

3.Restart Nautilius.

4.Right-click on a file or directory, you will see this:

open in nautilus

Source: https://help.ubuntu.com/community/NautilusScriptsHowto

-1

Just Run this command on your terminal:

wget -qO- https://raw.githubusercontent.com/cra0zy/code-nautilus/master/install.sh | bash

Source: itectec.com

tinlyx
  • 3,328
-1

also if you use VSCodium you can install my version of "python3-nautilus"

run

wget -qO- https://raw.githubusercontent.com/akifkadioglu/codium-nautilus/master/install.sh | bash

thank you Harry