Zsh command line editor: go back to previous lines when entering command

Note that I'm not talking about the previous lines in the story. I am talking about the previous lines in the current multi-line command.

When I enter a multi-line command in zsh, for example ( _indicates cursor):

$ for i in {1..5}; do
for> echo i_

At this point i might change my mind and want to let iloop through {1..10}instead, so i need to go back to the previous line. However, I can't figure out how to do this, as ⌫, or ←, or C-b, or whatever I can think of all stops at the beginning of the second line. So, is it possible at all to move back? Thanks in advance.

This is actually not limited to zsh. For example, I never thought about this in bash.

I have already spent a lot of time on Googling without any conclusions, so please excuse me and blame my Google-fu if this is obvious.


For your reference, I use keybinding Emacs and

$ bindkey | grep delete
"^D" delete-char-or-list
"^H" backward-delete-char
"^[[3~" delete-char
"^?" backward-delete-char

Not sure if this will help.

+4
source share
3 answers

I don't think this is possible, but there are other ways:

  • You can simply write everything in one line. Editing it is not easy, but multi-line strings are also easy to edit.
  • You can associate some key (for example, <C-Enter>if you can say that your terminal does not output <C-m>in this case) on

    function _-add-newline()
    {
        LBUFFER="$LBUFFER"$'\n'
    }
    zle -N add-newline _-add-newline
    bindkey "\Ca" add-newline
    

    . , <C-a>, , , . , , /, .

  • for x in y ; do<CR>echo foo<CR><C-c><Up>, for x in y ; do\necho foo , . : <CR> (, <C-c> ) <C-c>, ; , done ( <CR> ). <C-c> .
  • accept-line , , , , , \n ( ) accept-line, accept-line. , "".
+1

visual bash vim.

.bashrc .

set -o vi

# I do not remember which one of these is used by `v`, so I set both
export VISUAL=/usr/bin/nano
export EDITOR=/usr/bin/nano

bash, Esc, normal. v nano. nano. , .


zsh rc. zsh.

bindkey -v
autoload -U edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
+5

.

pres Esc + X , push-line-or-edit ( , Tab ) , return.

The invitation will change to the traditional one, discarding your part for>from the continuation, and you will have a new buffer filled with all your previously typed lines, which, of course, you can now easily edit using well-known C-aor C-b.

+3
source

Source: https://habr.com/ru/post/1541843/


All Articles