-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show current mode in ZSH Vi mode #5438
Comments
Is there any way this feature could be added to |
@stepanzak I was playing around with this and adding the following snippet already enables this. Currently thinking about how to enable that from the configuration. .zshrcbindkey -v
_omp_redraw-prompt() {
local precmd
for precmd in $precmd_functions; do
$precmd
done
zle .reset-prompt
}
function _omp_zle-keymap-select() {
if [ "${KEYMAP}" = 'vicmd' ]; then
export POSH_VI_MODE="command"
else
export POSH_VI_MODE="insert"
fi
_omp_redraw-prompt
}
_omp_create_widget zle-keymap-select _omp_zle-keymap-select
# reset to default mode at the end of line input reading
function _omp_zle-line-finish() {
export POSH_VI_MODE="insert"
}
_omp_create_widget zle-line-finish _omp_zle-line-finish
# Fix a bug when you C-c in CMD mode, you'd be prompted with CMD mode indicator
# while in fact you would be in INS mode.
# Fixed by catching SIGINT (C-c), set mode to INS and repropagate the SIGINT,
# so if anything else depends on it, we will not break it.
TRAPINT() {
export POSH_VI_MODE="insert"
return $(( 128 + $1 ))
} And use the following code block to display this: mytheme.omp.json{
"type": "text",
"style": "plain",
"template": "{{ if .Env.POSH_VI_MODE }}({{ .Env.POSH_VI_MODE }}) {{ end }}"
} |
Hey, would it be possible for you to also make it where the prompt symbol can change based on what mode we're in? Possibly integrate with the zsh-vi-mode plugin as an additional nicety! |
@NovaViper that's not something we do, but changing the icon is rather straightforward with the use of a template |
@JanDeDobbeleer Ah ok! I was wondering because I can't consistently get the variable to display in the prompt. I can get it to show This is my zshrc (I'm using NixOS with Home-Manager to setup zsh), https://gist.github.com/NovaViper/6eeb096936b0c52290632986a3a18d38 |
# OMP zsh-vi-mode integration
_omp_redraw-prompt() {
local precmd
for precmd in "${precmd_functions[@]}"; do
"$precmd"
done
zle .reset-prompt
}
export POSH_VI_MODE="I"
function zvm_after_select_vi_mode() {
case $ZVM_MODE in
$ZVM_MODE_NORMAL)
POSH_VI_MODE="N"
;;
$ZVM_MODE_INSERT)
POSH_VI_MODE="I"
;;
$ZVM_MODE_VISUAL)
POSH_VI_MODE="V"
;;
$ZVM_MODE_VISUAL_LINE)
POSH_VI_MODE="V-L"
;;
$ZVM_MODE_REPLACE)
POSH_VI_MODE="R"
;;
esac
_omp_redraw-prompt
} [[blocks.segments]]
leading_diamond = ''
trailing_diamond = ' '
template = '{{ if .Env.POSH_VI_MODE }}{{ .Env.POSH_VI_MODE }}{{ end }}'
foreground = 'red'
background = '#3C3836'
type = 'text'
style = 'diamond'
foreground_templates = [
"{{if contains \"N\" .Env.POSH_VI_MODE}}blue{{end}}",
"{{if contains \"I\" .Env.POSH_VI_MODE}}magenta{{end}}",
"{{if contains \"V\" .Env.POSH_VI_MODE}}cyan{{end}}",
"{{if contains \"V-L\" .Env.POSH_VI_MODE}}cyan{{end}}",
"{{if contains \"R\" .Env.POSH_VI_MODE}}yellow{{end}}",
] |
@Frestein Thanks! I took your example and further modified it to allow for the prompt character to change!
This is translated from my json file that my NixOS configuration generates, may not work exactly as intended.
Quick Edit: Here's a reference of the commit for anyone who needs it for their own NixOS setup! NovaViper/NixConfig@13e0d01 |
Code of Conduct
What would you like to see added?
In ZSH, you can enable Vi mode with
bindkey -v
.Powerlevel10k has (had) a feature that shows current mode (
normal
/insert
/replace
etc.) and immediately updates it on change.I would love to be able to do the same in omp, since it's really annoying to use the Vi mode whilst not being able to tell whether I'm in
insert
mode or not.The text was updated successfully, but these errors were encountered: