<C-W> deletes all texts up to the beginning, not a word, in REPL

I think that <C-W> in JuliaREPL should remove text a word at once, not all texts up to the beginning.

Is there any way to configure it as I want?

Note: I’m using OhMyREPL.

Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.7.0)
  CPU: Apple M1
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, westmere)

I am not using OhMyRepl, and find that it does remove words one at a time.

Oh, really?

For instance, suppose that there are texts like include(test/runtests (not closed parenthesis).
In the above case, how does it change when pressing ?

For me, it deletes all.

EDIT: disable OhMyREPL and try it again also shows the same result to me :frowning:

Try adding whitespace.

Sorry but I’m not talking about space-separated words. Please see the example.

In most terminal environments such as in macOS and Ubuntu (with zsh in my case), <C-W> removes a word at once like this: qwer/asdfqwer/.
So I hope that <C-W> in JuliaREPL changes include("test/runtests to include("test/.

I think you are looking for Meta (Alt) + Backspace.

julia> include("test/runtests.jl")
# Alt- Backspace
julia> include("test/runtests.
# Alt- Backspace
julia> include("test/
# Alt- Backspace
julia> include("
# Alt- Backspace

Try this:

julia> mode = Base.active_repl.interface.modes[1]
"Prompt(\"julia> \",...)"

julia> mode.keymap_dict['\x17'] = mode.keymap_dict['\e']['\b']
#112 (generic function with 1 method)
1 Like

It works! But I’m little bit worried about that this change might have some potential issues.
If you don’t mind, can you explain it in details?

We are simply modifying the keymaps originally stated in julia/LineEdit.jl at master · JuliaLang/julia · GitHub . In this case, we just borrowed the the function for Alt-Backspace ("\e\b") to be used for Ctrl-W ("^W", aka '\x17').

1 Like

Thank you very much.

Is it also possible to add it to startup.jl?
Cuz I’ve tried it but this error occurs:

ERROR: LoadError: UndefVarError: active_repl not defined
 [1] getproperty(::Module, ::Symbol) at ./Base.jl:26
 [2] top-level scope at /Applications/Julia-1.5.app/Contents/Resources/julia/etc/julia/startup.jl:22
 [3] include(::Function, ::Module, ::String) at ./Base.jl:380
 [4] include at ./Base.jl:368 [inlined]
 [5] load_julia_startup() at ./client.jl:324
 [6] exec_options(::Base.JLOptions) at ./client.jl:267
 [7] _start() at ./client.jl:506
in expression starting at /Applications/Julia-1.5.app/Contents/Resources/julia/etc/julia/startup.jl:22


Base.active_repl.interface.modes[1].keymap_dict['\x17'] = Base.active_repl.interface.modes[1].keymap_dict['\e']['\b']

You probably need to add it to atreplinit in startup.jl:

atreplinit() do repl
   repl.interface.modes[1].keymap_dict['\x17'] = repl.interface.modes[1].keymap_dict['\e']['\b']

I have not tested this.

Sorry but it does not work.

I gave up :frowning:

Try this in startup.jl

import REPL.LineEdit: MIState, edit_delete_prev_word
atreplinit() do repl
          Dict('\x17' => (s::MIState,o...)->edit_delete_prev_word(s)))
1 Like

Thanks a lot.

I found that keymapping “after” OhMyREPL does not properly work.
So I moved lines about keymapping at the beginning of startup.jl as follows, and it works.

import REPL
import REPL.LineEdit: MIState, edit_delete_prev_word, ModeState
atreplinit() do repl
    repl.interface = REPL.setup_interface(repl; extra_repl_keymap = Dict("^W" => "\e\b"))

Reference: Customizing-keybindings

1 Like