* vi-mode: editor function @ 2014-05-14 20:18 Sepp Tannhuber 2014-05-15 1:48 ` Bart Schaefer 0 siblings, 1 reply; 5+ messages in thread From: Sepp Tannhuber @ 2014-05-14 20:18 UTC (permalink / raw) To: zsh-users [-- Attachment #1: Type: text/plain, Size: 1560 bytes --] Dear all, I have written a theme for the oh-my-zsh prompt from robbyrussel because I was sometimes confused about the different vi modes. My prompt shows, at a glance, which vi mode is active, similar to the vim airline plugin. For the indicators, the theme uses functions like the following: vi-insert() { MODE="INSERT" builtin zle .vi-insert } zle -N vi-insert bindkey -M vicmd "i" vi-insert vi-replace() { MODE="REPLACE" builtin zle .vi-replace } zle -N vi-replace bindkey -M vicmd "R" vi-replace The MODE variable finally sets the indicator for the prompt. This works very well, except in the following case. When I call the editor with [ESC] [v] I can edit the command line with vi, as expected. But after closing the editor, the zsh prompt is in INSERT mode. It has been in NORMAL mode before. And this is not considered in my script. Thus, I would like to know, whether there is a function, equivalent to the ones above. I am looking for something like this: vi-editor() { MODE="INSERT" # prompt is in INSERT mode after editing builtin zle .vi-editor } zle -N vi-editor bindkey -M vicmd "v" vi-editor Unfortunately I could not find something like vi-editor it in the zshzle manual. Has anybody an idea what I can use instead? Or what is the default vicmd for [v]? Best regards Joseph ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: vi-mode: editor function 2014-05-14 20:18 vi-mode: editor function Sepp Tannhuber @ 2014-05-15 1:48 ` Bart Schaefer 2014-05-15 9:50 ` vi-mode: editor function [solved] Sepp Tannhuber 0 siblings, 1 reply; 5+ messages in thread From: Bart Schaefer @ 2014-05-15 1:48 UTC (permalink / raw) To: zsh-users On May 14, 9:18pm, Sepp Tannhuber wrote: } Subject: vi-mode: editor function } } I have written a theme for the oh-my-zsh prompt from robbyrussel } because I was sometimes confused about the different vi modes. My } prompt shows, at a glance, which vi mode is active, similar to the vim } airline plugin. [...] } Unfortunately I could not find something like vi-editor it in the } zshzle manual. Has anybody an idea what I can use instead? Or what is } the default vicmd for [v]? There is no default binding for v in vicmd mode, so you are encountering something installed for you by oh-my-zsh. Most likely it is the user- contributed edit-command-line widget (man zshcontrib). If oh-my-zsh hasn't already pre-empted the zle-line-init, zle-line-finish, and zle-keymap-select widgets, you might find it more effective to set the MODE variable with those, rather than trying to override all the individual widgets that might change mode. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: vi-mode: editor function [solved] 2014-05-15 1:48 ` Bart Schaefer @ 2014-05-15 9:50 ` Sepp Tannhuber 2014-05-15 11:18 ` Julien Jehannet 0 siblings, 1 reply; 5+ messages in thread From: Sepp Tannhuber @ 2014-05-15 9:50 UTC (permalink / raw) To: Bart Schaefer, zsh-users [-- Attachment #1: Type: text/plain, Size: 1521 bytes --] Dear Bart, thank you for the hint. Indeed, I found an edit-command-line module in zshcontrib. And yes, it is loaded by oh-my-zsh. So I could fix my theme script. Unfortunately, I have no idea how to set the MODE variable the way you mentioned. If anybody wants to tell me, you can find the script at https://github.com/tannhuber/oh-my-zsh/blob/master/themes/budspencer.zsh-theme But don't waste your time. Everything is working well, now. Thank you Joseph Bart Schaefer <schaefer@brasslantern.com> schrieb am 3:50 Donnerstag, 15.Mai 2014: On May 14, 9:18pm, Sepp Tannhuber wrote: } Subject: vi-mode: editor function } } I have written a theme for the oh-my-zsh prompt from robbyrussel } because I was sometimes confused about the different vi modes. My } prompt shows, at a glance, which vi mode is active, similar to the vim } airline plugin. [...] } Unfortunately I could not find something like vi-editor it in the } zshzle manual. Has anybody an idea what I can use instead? Or what is } the default vicmd for [v]? There is no default binding for v in vicmd mode, so you are encountering something installed for you by oh-my-zsh. Most likely it is the user- contributed edit-command-line widget (man zshcontrib). If oh-my-zsh hasn't already pre-empted the zle-line-init, zle-line-finish, and zle-keymap-select widgets, you might find it more effective to set the MODE variable with those, rather than trying to override all the individual widgets that might change mode. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: vi-mode: editor function [solved] 2014-05-15 9:50 ` vi-mode: editor function [solved] Sepp Tannhuber @ 2014-05-15 11:18 ` Julien Jehannet 2014-05-15 14:32 ` Sepp Tannhuber 0 siblings, 1 reply; 5+ messages in thread From: Julien Jehannet @ 2014-05-15 11:18 UTC (permalink / raw) To: Sepp Tannhuber; +Cc: zsh-users [-- Attachment #1.1: Type: text/plain, Size: 1972 bytes --] FWIW, you could simplify your builtin redefinitions by using the ZLE_STATE variable. Changes from 4.3.11: The parameter ZLE_STATE, available in user-defined line editor widgets, gives information on the state of the line editor. Currently this is whether the line editor is in insert or overwrite mode. 2014-05-15 11:50 GMT+02:00 Sepp Tannhuber <sepp.tannhuber@yahoo.de>: > Dear Bart, > > thank you for the hint. Indeed, I found an edit-command-line module in > zshcontrib. > And yes, it is loaded by oh-my-zsh. So I could fix my theme script. > > Unfortunately, I have no idea how to set the MODE variable the way you > mentioned. > If anybody wants to tell me, you can find the script at > > https://github.com/tannhuber/oh-my-zsh/blob/master/themes/budspencer.zsh-theme > But don't waste your time. Everything is working well, now. > > Thank you > Joseph > Bart Schaefer <schaefer@brasslantern.com> schrieb am 3:50 Donnerstag, > 15.Mai 2014: > > On May 14, 9:18pm, Sepp Tannhuber wrote: > } Subject: vi-mode: editor function > > } > } I have written a theme for the oh-my-zsh prompt from robbyrussel > } because I was sometimes confused about the different vi modes. My > } prompt shows, at a glance, which vi mode is active, similar to the vim > } airline plugin. > [...] > } Unfortunately I could not find something like vi-editor it in the > } zshzle manual. Has anybody an idea what I can use instead? Or what is > } the default vicmd for [v]? > > There is no default binding for v in vicmd mode, so you are encountering > something installed for you by oh-my-zsh. Most likely it is the user- > contributed edit-command-line widget (man zshcontrib). > > If oh-my-zsh hasn't already pre-empted the zle-line-init, zle-line-finish, > and zle-keymap-select widgets, you might find it more effective to set the > MODE variable with those, rather than trying to override all the individual > widgets that might change mode. -- J u l i e n J e h a n n e t [-- Attachment #1.2: Type: text/html, Size: 2660 bytes --] [-- Attachment #2: budspencer.zsh-theme.patch --] [-- Type: text/x-diff, Size: 2552 bytes --] --- budspencer.zsh-theme.orig 2014-05-15 12:47:04.000000000 +0200 +++ budspencer.zsh-theme 2014-05-15 13:16:35.000000000 +0200 @@ -162,76 +162,6 @@ } # Vi modes -vi-add-eol() { - ZSH_VI_MODE="INSERT" - builtin zle .vi-add-eol -} -zle -N vi-add-eol -bindkey -M vicmd "A" vi-add-eol - -vi-add-next() { - ZSH_VI_MODE="INSERT" - builtin zle .vi-add-next -} -zle -N vi-add-next -bindkey -M vicmd "a" vi-add-next - -vi-change() { - ZSH_VI_MODE="INSERT" - builtin zle .vi-change -} -zle -N vi-change -bindkey -M vicmd "c" vi-change - -vi-change-eol() { - ZSH_VI_MODE="INSERT" - builtin zle .vi-change-eol -} -zle -N vi-change-eol -bindkey -M vicmd "C" vi-change-eol - -vi-change-whole-line() { - ZSH_VI_MODE="INSERT" - builtin zle .vi-change-whole-line -} -zle -N vi-change-whole-line -bindkey -M vicmd "S" vi-change-whole-line - -vi-insert() { - ZSH_VI_MODE="INSERT" - builtin zle .vi-insert -} -zle -N vi-insert -bindkey -M vicmd "i" vi-insert - -vi-insert-bol() { - ZSH_VI_MODE="INSERT" - builtin zle .vi-insert-bol -} -zle -N vi-insert-bol -bindkey -M vicmd "I" vi-insert-bol - -vi-open-line-above() { - ZSH_VI_MODE="INSERT" - builtin zle .vi-open-line-above -} -zle -N vi-open-line-above -bindkey -M vicmd "O" vi-open-line-above - -vi-open-line-below() { - ZSH_VI_MODE="INSERT" - builtin zle .vi-open-line-below -} -zle -N vi-open-line-below -bindkey -M vicmd "o" vi-open-line-below - -vi-substitute() { - ZSH_VI_MODE="INSERT" - builtin zle .vi-substitute -} -zle -N vi-substitute -bindkey -M vicmd "s" vi-substitute - vi-cmd-mode() { ZSH_VI_MODE="NORMAL" builtin zle .vi-cmd-mode @@ -247,7 +177,6 @@ bindkey -M vicmd "R" vi-replace vi-edit-command-line() { - ZSH_VI_MODE="INSERT" vim_mode=$vim_ins_mode dir_mode=$dir_ins_mode fgcolor=136 @@ -264,27 +193,25 @@ vim_cmd_mode="%{%K{33}%}%{%F{0}%}" vim_rpl_mode="%{%K{160}%}%{%F{0}%}" vim_mode=$vim_ins_mode -fgcolor=136 -ZSH_VI_MODE="INSERT" function zle-keymap-select { -if [ "$ZSH_VI_MODE" = "INSERT" ] +if [ "$ZSH_VI_MODE" = "NORMAL" ] +then + vim_mode=$vim_cmd_mode + dir_mode=$dir_cmd_mode + fgcolor=33 +elif [[ "$ZLE_STATE" = *insert* ]] then fgcolor=136 vim_mode=$vim_ins_mode dir_mode=$dir_ins_mode -fi -if [ "$ZSH_VI_MODE" = "REPLACE" ] + ZSH_VI_MODE="INSERT" +elif [[ "$ZLE_STATE" = *overwrite* ]] then vim_mode=$vim_rpl_mode dir_mode=$dir_rpl_mode fgcolor=160 -fi -if [ "$ZSH_VI_MODE" = "NORMAL" ] -then - vim_mode=$vim_cmd_mode - dir_mode=$dir_cmd_mode - fgcolor=33 + ZSH_VI_MODE="REPLACE" fi zle reset-prompt } ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: vi-mode: editor function [solved] 2014-05-15 11:18 ` Julien Jehannet @ 2014-05-15 14:32 ` Sepp Tannhuber 0 siblings, 0 replies; 5+ messages in thread From: Sepp Tannhuber @ 2014-05-15 14:32 UTC (permalink / raw) To: Julien Jehannet; +Cc: zsh-users [-- Attachment #1: Type: text/plain, Size: 2373 bytes --] Dear Julien, I didn't know the ZLE_STATE variable before. There's also the KEYMAP variable with the two modes "main" and "vicmd". The combination of both variables does the trick. It seems a little bit weird that both variables cannot show all three modes correctly. Thank you very much Joseph Julien Jehannet <julien@smaf.org> schrieb am 13:28 Donnerstag, 15.Mai 2014: FWIW, you could simplify your builtin redefinitions by using the ZLE_STATE variable. Changes from 4.3.11: The parameter ZLE_STATE, available in user-defined line editor widgets, gives information on the state of the line editor. Currently this is whether the line editor is in insert or overwrite mode. 2014-05-15 11:50 GMT+02:00 Sepp Tannhuber <sepp.tannhuber@yahoo.de>: Dear Bart, > >thank you for the hint. Indeed, I found an edit-command-line module in zshcontrib. >And yes, it is loaded by oh-my-zsh. So I could fix my theme script. > >Unfortunately, I have no idea how to set the MODE variable the way you mentioned. >If anybody wants to tell me, you can find the script at > https://github.com/tannhuber/oh-my-zsh/blob/master/themes/budspencer.zsh-theme >But don't waste your time. Everything is working well, now. > >Thank you >Joseph >Bart Schaefer <schaefer@brasslantern.com> schrieb am 3:50 Donnerstag, 15.Mai 2014: > >On May 14, 9:18pm, Sepp Tannhuber wrote: >} Subject: vi-mode: editor function > >} >} I have written a theme for the oh-my-zsh prompt from robbyrussel >} because I was sometimes confused about the different vi modes. My >} prompt shows, at a glance, which vi mode is active, similar to the vim >} airline plugin. >[...] >} Unfortunately I could not find something like vi-editor it in the >} zshzle manual. Has anybody an idea what I can use instead? Or what is >} the default vicmd for [v]? > >There is no default binding for v in vicmd mode, so you are encountering >something installed for you by oh-my-zsh. Most likely it is the user- >contributed edit-command-line widget (man zshcontrib). > >If oh-my-zsh hasn't already pre-empted the zle-line-init, zle-line-finish, >and zle-keymap-select widgets, you might find it more effective to set the >MODE variable with those, rather than trying to override all the individual >widgets that might change mode. -- J u l i e n J e h a n n e t ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-05-15 14:39 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-05-14 20:18 vi-mode: editor function Sepp Tannhuber 2014-05-15 1:48 ` Bart Schaefer 2014-05-15 9:50 ` vi-mode: editor function [solved] Sepp Tannhuber 2014-05-15 11:18 ` Julien Jehannet 2014-05-15 14:32 ` Sepp Tannhuber
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/zsh/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).