OS
Windows 10
Java
11
jshell provides the ability to edit code snippets using an external editor.
jshell> /edit
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
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)
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.
The default external editor for jshell can be specified with one of the following environment variables:
JSHELLEDITOR
VISUAL
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 **
** VS Code is launched from jshell **
Recommended Posts