Skip to content

Instantly share code, notes, and snippets.

@abmantis
Last active October 15, 2023 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abmantis/dd372ec41eb654f2e79114ff3e2a49eb to your computer and use it in GitHub Desktop.
Save abmantis/dd372ec41eb654f2e79114ff3e2a49eb to your computer and use it in GitHub Desktop.
nvim + devcontainers (with clipboard support!)

Build container:

  • Run devcontainer up (.X11-unix is needed for clipboard to work)
devcontainer up --remove-existing-container --mount "type=bind,source=$HOME/.config/nvim,target=/nvim-config" --mount "type=bind,source=/tmp/.X11-unix,target=/tmp/.X11-unix" --workspace-folder .

Setup container:

TL;DR one-liner:

devcontainer exec --workspace-folder . --remote-env DISPLAY=$DISPLAY bash -c "sudo apt update && sudo apt install -y xclip &&  curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage && chmod +x nvim.appimage && ./nvim.appimage --appimage-extract && sudo mv squashfs-root /nvim && sudo ln -s /nvim/AppRun /bin/nvim && mkdir -p ~/.config/ && ln -s /nvim-config ~/.config/nvim"

Step by step:

  • Enter container:
devcontainer exec --workspace-folder . --remote-env DISPLAY=$DISPLAY zsh
  • Install xclip inside the container for clipboard:
sudo apt update && sudo apt install -y xclip
  • Instal nvim in the container (the AppImage ensures it is a recent version):
curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage
chmod +x nvim.appimage
./nvim.appimage --appimage-extract
sudo mv squashfs-root /nvim
sudo ln -s /nvim/AppRun /bin/nvim
  • Link nvim config to the correct place (until we can use XDG_CONFIG_HOME directly on devcontainer up):
mkdir -p ~/.config/ && ln -s /nvim-config ~/.config/nvim

Running nvim

devcontainer exec --workspace-folder . --remote-env DISPLAY=$DISPLAY bash -c "nvim ."

Tips and troubleshooting

Clipboard not working

If running Wayland, you may need to do the following on the host:

xhost +local:docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment