Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: vi-mode zle: how to delete past the start char of insert mode (like VIM 'backspace'=start option)

On 27/09/2009, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Sep 27,  4:03pm, Anton Sharonov wrote:
> }
> } After I type some text, leave insert mode, and enter it again,
> } and try to delete the text I entered [...]
> } I got cursor only till the point, where insert mode is started
> By way of explanation, zsh is faithfully emulating traditional "vi"
> behavior in this instance.  (If there's anyone familiar enough with
> both vi and vim to enumerate the differences, we might be able to
> put together a sample zshrc for vim emulation.)

Nice idea !

(Strictly speaking, that is probably not the best way to provide
just one single "VIM emulation zshrc". Vim tries to stay vi
compatible, it just adds a huge amount of options, which changes
"original vi" behaviour in all directions - I believe one will
find a lot of vim users, who still uses pretty much vi-compatible
setup, just out of habit or whatever. Therefore ideally sample
zshrc should contain kind of dictionary with examples of "the zsh
ways to emulate/tune of vim most popular options: 'backspace',
'iskeyword', ...").

> } Desired behaviour: <C-W>, <BS>, <C-U> should remove the WORD,
> } symbol, to the begin of line, respectively. (In VIM the
> } corresponding option is 'backspace', value "start" controls this
> } behaviour)
> }
> } How can I tell zshzle that I like to be able to delete past the
> } point of _start_ of the insert mode ?
> You can mostly get this by replacing the corresponding key bindings
> with the emacs-mode equivalents.  For example:
> bindkey -v
> bindkey "^W" backward-kill-word    # vi-backward-kill-word
> bindkey "^H" backward-delete-char  # vi-backward-delete-char
> bindkey "^U" kill-line             # vi-kill-line
> bindkey "^?" backward-delete-char  # vi-backward-delete-char

Thanks, suggested mappings are working fine for me. (With one
minor exception - I should use of backward-kill-line instead of
just kill-line).

> These may not work precisely as you desire when you are editing a
> multi-line buffer, but should be OK for most uses.  You may need to
> fiddle with the value of the WORDCHARS variable to get vim-like
> word motions out of backward-kill-word, or consider looking at the
> select-word-style function and delete-whole-word-match (look in the
> User Contributions section of the manual, under ZLE Functions).

Its happens that the backward-kill-word by default acts in the
same way as one see ^W works in bash - this behaviour is fully
satisfactory for me at the moment. Out of curiosity I have
however played a bit with WORDCHARS value.

Thanks a lot for your help !


Messages sorted by: Reverse Date, Date, Thread, Author