Specify VS Code as the default editor for jshell

environment

OS

Windows 10

Java

11

Use an external editor with jshell

jshell provides the ability to edit code snippets using an external editor.

jshell> /edit

jshell.jpg

By default, a super simple editor like this will be launched. [^ 1]

[^ 1]: Simple enough that you can't redo or redo editing with Ctrl + Z or Ctrl + Y

jshell.jpg

If you edit the code here and close the editor with ʻExit`, the code written in the editor will be registered as a snippet.

If there are multiple snippets, you can specify / edit <snippet ID> to edit only the specified snippet. (If you don't specify a snippet ID, all snippets will be displayed in the editor)

Specify VS Code in the external editor

The external editor used by / edit can be specified in the form/ set editor <command to start the editor>.

jshell> /set editor "F:\\ProgramFiles\\Microsoft VS Code\\Code.exe" -w
|The editor is set to: F:\ProgramFiles\Microsoft VS Code\Code.exe -w

If you specify VS Code, set the path to the VS Code exe and the -w option. -w is an option that does not return control to the invocation source until the file is closed, otherwise it will not work well [^ 2]. Don't forget to escape the backslash.

[^ 2]: Temporary files created for the editor are deleted when control returns to jshell, making it impossible to edit the code in the editor.

Now when you open the editor with / edit, VS Code will open. Closing the file returns control to jshell.

jshell.jpg

Specify the default external editor

The default external editor for jshell can be specified with one of the following environment variables:

  1. JSHELLEDITOR
  2. VISUAL
  3. EDITOR

↑ has a higher priority, and the information of the environment variable for which the editor was set earlier is adopted.

In other words, if you set the environment variable JSHELLEDITOR to the same information specified in / set editor earlier, you do not need to / set editor every time.

** Value set in environment variable **

jshell.jpg

** VS Code is launched from jshell **

jshell.gif

reference

Recommended Posts

Specify VS Code as the default editor for jshell
Oracle Live for the Code
Pre-written source code for the activity
Change the default timezone for the rails app
VS Code plugin recommended for programming school students
Specify the timeout for each path with Rack :: Timeout
Specify the default value with @Builder of Lombok