3

I am desperately seaching for a way to enable classic navigation and selection in zsh shell.. Meaning, I want to be able to: - select char by char in zsh using shift+left/right - move word by word in zsh using control+left/right - select word by word in zsh using ctrl+shift+left/right

I have been able, using a few stupid hacks and solutions I found on different related topics, to do the 2 first points of my list, but I cannot get a simple solution to make my 3rd point work properly... Does anyone have an idea on how to do this? I am using gnome-terminal, but I don't mind switching to an other one if it is needed to do what I want, as long as the new one allows me to copy/paste/scroll using the mouse.

I hope you have a solution to my problem =)

lagarkane
  • 915
  • 2
  • 9
  • 22
  • Could you please share, what you already have? What exactly does not work in the third case? Also, are you looking to emulate mouse-selection (which would be a feature of the terminal) or to create more convenient bindings for zsh regions (`set-mark-command`)? – Adaephon Jul 24 '14 at 11:19
  • Does this answer your question? [Zsh zle shift selection](https://stackoverflow.com/questions/5407916/zsh-zle-shift-selection) – Jakub Jirutka Mar 14 '22 at 00:54

1 Answers1

3

Ok this is what I currently have, in my .zshrc, to control the keybinding:

function zle-line-init {
    marking=0
}
zle -N zle-line-init

function select-char-right {
    if (( $marking != 1 ))
    then
        marking=1
        zle set-mark-command
    fi
    zle .forward-char
}
zle -N select-char-right

function select-char-left {
    if (( $marking != 1 ))
    then
        marking=1
        zle set-mark-command
    fi
    zle .backward-char
}
zle -N select-char-left

function forward-char {
    if (( $marking == 1 ))
    then
        marking=0
        NUMERIC=-1 zle set-mark-command
    fi
    zle .forward-char
}
zle -N forward-char

function backward-char {
    if (( $marking == 1 ))
    then
        marking=0
        NUMERIC=-1 zle set-mark-command
    fi
    zle .backward-char
}
zle -N backward-char

function delete-char {
    if (( $marking == 1 ))
    then
        zle kill-region
        marking=0
    else
        zle .delete-char
    fi
}
zle -N delete-char

bindkey ';6D' select-word-left ## not working yet                                                                                                                                                                                                                               
bindkey ';6C' select-word-right ## not working yet                                                                                                                                                                                                                              
bindkey ';2D' select-char-left   # assuming xterm                                                                                                                                                                                                                               
bindkey ';2C' select-char-right  # assuming xterm                                                                                                                                                                                                                               
bindkey ';5D' backward-word
bindkey ';5C' forward-word
bindkey '^[[3~' delete-char

with this, I can:

  • move word by word with control

  • select a region to delete with shift (only problem, I have no visual on the marked region)

  • a delete key that works

Sorry for the confusion, I am currently on xterm terminal (just changed my desktop environment to xfce4)

I would still like to mark a region to kill using ctrl+shift+arrows, haven't been able to do this yet because I don't know how to get the number of chars moved with forward/backward-word.. In a better world, I would also like to have an highlighted marked region... =) Any idea?

lagarkane
  • 915
  • 2
  • 9
  • 22