Skip to content

Instantly share code, notes, and snippets.

@mordr
Last active February 27, 2025 13:53
Show Gist options
  • Select an option

  • Save mordr/3c2df494c690672247c720f66f0fb613 to your computer and use it in GitHub Desktop.

Select an option

Save mordr/3c2df494c690672247c720f66f0fb613 to your computer and use it in GitHub Desktop.
Set Visual Studio Code as default editor for kubectl

Set KUBE_EDITOR to Visual Studio Code, assumes 'code' is in PATH

export KUBE_EDITOR='code --wait'

Running k edit ... will open up the yaml using Visual Studio Code.

@mousavian

mousavian commented Jun 14, 2019

Copy link
Copy Markdown
EDITOR='open -a "Visual Studio Code" --wait' kubectl

^ inline temporary editor change for mac users

@MajorBreakfast

Copy link
Copy Markdown

@mousavian kubeclt?

@bodinsamuel

Copy link
Copy Markdown

thanks 🙏

@elgammalqa

Copy link
Copy Markdown

Thanks

@officialdarnyc

Copy link
Copy Markdown

Thanks

@ashconnell

Copy link
Copy Markdown

Legend!

@MissakaI-ObjectOne

Copy link
Copy Markdown

For PowerShell use
$env:KUBE_EDITOR="code --wait"

@willyg123

willyg123 commented Jun 23, 2022

Copy link
Copy Markdown

To make this permanent, edit ~/.bash-profile with code ~/.bash-profile and enter this into it:

export KUBE_EDITOR='code --wait'

@azerafati

Copy link
Copy Markdown

indeed opens up vscode just fine, but ‌I‌ can't make a change and save it. it says Edit cancelled, no changes made. tried it with --wait flag

@allidoiswin10

Copy link
Copy Markdown

Awesome!

@AL1L

AL1L commented Jan 25, 2024

Copy link
Copy Markdown

Thank

@vegetablest

Copy link
Copy Markdown

On macOS, has anyone encountered the problem that closing the editing page will not save the changes, and need to exit the vscode process to save the changes.

@parveenksharma

Copy link
Copy Markdown

On my mac Ventura in my ~/.bash_profile I have :
export KUBE_EDITOR='open -a "Visual Studio Code" --wait'

and it is opening the new VSCode window with command on terminal:
kubectl edit pod fooapp

The problem is once I am done editing the yml and save it and close the associated VSCode window the control is not returning to terminal.
For that I have to Quit VSCode completely.

This is very inconvenient as this is resulting in closing all my other open / work in progress files with VSCode .

Please suggest.

@ivaylokardashev

Copy link
Copy Markdown

$env:KUBE_EDITOR="code --wait"

Thanx you

@WizzzOzzz-Ori

Copy link
Copy Markdown

thanks mate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment