Home » Java » Core Java » Set Visual Studio Code as default editor in jshell

About Rafal Borowiec

Rafal Borowiec
Software developer, Team Leader, Agile practitioner, occasional blogger, lecturer. Open Source enthusiast, quality oriented and open-minded.

Set Visual Studio Code as default editor in jshell

Java Shell (jshell) is an interactive tool for learning and prototyping in Java. It was introduced with Java 9 and since then I use it ocassionally either for some quick prototyping, during presentations or simply to verify new features in the Java language. Since jshell is a command line tool (with basic intellisense) editing files in jshell is not the best expierience. Fortunatelly, jshell allows changing the default editor and set it to the one of your choice, including Visual Studio Code, Atom or Sublime.

My primary and favorite IDE is IntelliJ it is pretty havy for some really basic source code editing and its built-in support for jshell is far from perfect. So why not to set Visual Studio Code as a default jshell editor?

Set editor for the current jshell session

Open jshell in the terminal

1
$ jshell

Run jshell command

1
2
jshell> /set editor /usr/local/bin/code -w
|  Editor set to: /usr/local/bin/code -w

The -w option sets waiting for the file to be closed before returning.

Now you can edit the current session by running the edit command:

1
jshell> /edit

This will open Visual Studio Code (it opens new tab if you have VSC opened). You can edit the file and once you are done with editing save and close the file.

Set editor and retain the setting between jshell sessions

If you want to retain the setting between jshell sessions you need to add retain flag while setting the editor:

1
2
3
jshell> /set editor -retain /usr/local/bin/code -w
|  Editor set to: /usr/local/bin/code -w
|  Editor setting retained: /usr/local/bin/code -w

Learn about the tools I use on macOS in this post: macOS: essential tools for (Java) developer]

The solution presented here will also work for Atom or any other editor with the option to wait for the opened file to be closed before returning.

See also

Do you want to switch Java SDKs easily so that you can play with new Java features in jshell? Use SDKMAN! Check this blog post and learn how to get started with SDKMAN!: Manage multiple Java SDKs with SDKMAN! with ease

Published on Java Code Geeks with permission by Rafal Borowiec, partner at our JCG program. See the original article here: Set Visual Studio Code as default editor in jshell

Opinions expressed by Java Code Geeks contributors are their own.

(0 rating, 0 votes)
You need to be a registered member to rate this.
1 Comment Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
ElenaGillbert Recent comment authors

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
newest oldest most voted
Notify of
ElenaGillbert
Guest

Hi..
I’m Elena gillbert.The -w option sets waiting for the file to be closed before returning. This will open Visual Studio Code (it opens new tab if you have VSC opened). You can edit the file and once you are done with editing save and close the file.