Your example appears to work just fine using xterm, so I don't think it is your .vimrc
that is the problem.
Digging a little deeper, it appears that PuTTY doesn't appear to implement the OSC escape code that you are using to change the colour of the cursor (see do_osc
in terminal.c
in the PuTTY sources). Browsing the sources, I couldn't find any other mechanism to do something similar, either. This means that there probably isn't going to be an easy way to get this working in PuTTY.
Your solutions are thus likely to be limited to:
- Trying to plead with the PuTTY authors to implement the relevant OSC escape code;
- Changing your terminal program; or
- Finding another way to let vim know what mode you are in.
I suspect the third is going to be the easiest, unfortunately.
(1). For some reason, bindkey behaves oddly when it comes to "/": <esc>
followed quickly by /
is interpreted as <esc-/>
. (I observed this behavior the other day; not quite sure what causes it.) I don't know if this is a bug or a feature, and if it's a feature if it can be disabled, but you can work around it fairly easily.
This key combo is probably bound to _history-complete-older
, which is generating the undesired result – you can use bindkey -L
to see the if this is the case.
At any rate, if you don't mind sacrificing the actual <esc-/>
(pressed together, as a chord) binding, you can re-bind it to the vi-mode history search command, so that typing <esc>
followed by /
does the same thing at any typing speed. =)
Since this will be treated as a chord, it won't have the effect of first entering vi command mode, so we'll have to make sure that happens first. First, you need to define a function; put it somewhere in your fpath
if you use that, or put it in your .zshrc otherwise:
vi-search-fix() {
zle vi-cmd-mode
zle .vi-history-search-backward
}
The rest goes in your .zshrc either way:
autoload vi-search-fix
zle -N vi-search-fix
bindkey -M viins '\e/' vi-search-fix
Should be good to go.
(2). You can fix the backspace key as follows:
`bindkey "^?" backward-delete-char`
Also, if you want similar behavior for other vi style commands:
bindkey "^W" backward-kill-word
bindkey "^H" backward-delete-char # Control-h also deletes the previous char
bindkey "^U" backward-kill-line
Best Answer
1.) (see http://zshwiki.org/home/examples/zlewidgets and http://pthree.org/2009/03/28/add-vim-editing-mode-to-your-zsh-prompt/ ):
Where:
"RPS" stands for 'right prompt string' and defines the prompt appearing on the right hand side of the terminal, and the ${variable/pattern/replacement} syntax is that of 'parameter expansion', see: http://mywiki.wooledge.org/BashSheet#Parameter_Operations.
'zle -N' causes the user-definable widgets 'zle-line-init' and 'zle-keymap-select' to be bound (to shell functions of same names), so that they will be called when the line editor is initialised and the keymap is changed respectively, see: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#SEC125.
2.) i suspect that you have to write another zsh-widget to do that, get inspired by the first of the two links for the first problem.