# How to modify the default editor of JShell in Java 9?

JavaObject Oriented ProgrammingProgramming

JShell implements REPL (Read-Evaluate-Print Loop) that reads the code from the command-line, evaluates the given snippet, and prints the result back to us.

In JShell, it's possible to edit code from the default JShell editor by using JShell Editor Pad. We can also use the "/set" command to modify the default editor in order to define another one. When launching the "/edit" command, this editor can be used. In order to perform this operation, we can simply launch the "/set editor [editor]" command.

Suppose we want to set the Notepad application as the default program for editing code, then just type the command: "/set editor notepad.exe".

jshell> /set editor
|  /set editor -default

jshell> int i = 20
i ==> 20

jshell> double j = 30.0
j ==> 30.0

jshell> /edit

Now, if we want to modify the code entered in the command prompt by using the "/edit" command, it can open a notepad application as below.

If we can modify the JShell editor by entering a non-existent program or an incorrect path, JShell can't display an error message when we execute the "/edit" command. We only get an error message when trying to open the editor as below.

jshell> /set editor emacs
|  Editor set to: emacs

jshell> /set editor
|  /set editor emacs

jshell> /edit
|  Edit Error: process IO failure: Cannot run program "emacs": CreateProcess error=2,
The system cannot find the file specified
Updated on 13-Apr-2020 09:12:48