Skip to content
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

Wiki: change prompt in vi mode issue: prompt disappears in tmux session #184

Closed
srustamo opened this issue Jan 18, 2016 · 19 comments
Closed

Comments

@srustamo
Copy link

Wiki suggests this solution to changing prompt depending on a vi mode.

All's well, works great, except in a tmux session. The prompt is there initially, but disappears after running any command. After running a command, the prompt remains in insert mode, hitting Esc or any other key restores the prompt character (in normal or insert mode respectively).

@mafredri
Copy link
Collaborator

I'm pretty sure this problem is related to vi-mode moving the cursor and the preprompt updating can't calculate the correct position to redraw. If you could provide a screencast that would be very helpful (and key combinations used would make it even better)!

@srustamo
Copy link
Author

Here's a gist with my .zshrc.
Here's the screencast.

I should've mentioned before, that if pwd is git controlled, then there are no problems with prompt character in tmux. This is also shown in the screencast.

@mafredri
Copy link
Collaborator

Thanks for screencasts! I can't reproduce this myself, but I do see some problems in your zshrc.

First off: you should put these at the very end of your .zshrc, they must be last (it's stated in their readmes but this is a very common error none-the-less, easily overlooked).

source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /usr/local/opt/zsh-history-substring-search/zsh-history-substring-search.zsh

Secondly, you might also want to use this function instead:

function zle-line-init zle-keymap-select {
    zle .reset-prompt
}

The . in front of reset-prompt ensures the original reset-prompt is called and not an aliased one.

Sidenote: Also, there really isn't any need to redefine prompt in the zle functions, once above (but after prompt pure) is enough.

Finally, if none of this helps, what version of iTerm are you running? I notice it says just iTerm on your machine, not iTerm2. Might be worth looking at upgrading.

@srustamo
Copy link
Author

Thanks! Following your advice fixed the problem.
About iTerm says it is iTerm2, Build 2.1.4.

If I may expand this thread a bit, the only time when the prompt char still disappears is when resizing the iTerm2 window (after applying the changes to .zshrc you suggested).

Creating or deleting tmux panes does not affect the prompt char.

@mafredri
Copy link
Collaborator

Thanks! Following your advice fixed the problem.

Great!

About iTerm says it is iTerm2, Build 2.1.4.

Oh, my bad. I guess only the beta / nightly says iTerm2.

If I may expand this thread a bit, the only time when the prompt char still disappears is when resizing the iTerm2 window

If you're using zsh >= 5.1.1 you might try adding to your zshrc (without affecting pure functionality).

TRAPWINCH() {
    zle && zle .reset-prompt && zle -R
}

It will trigger on window resize. Not sure if the zle -R is required though.

@srustamo
Copy link
Author

Works perfectly. Thank you so much!

@srustamo
Copy link
Author

Hello. The problem of missing prompt char in tmux session reappeared. The problem is exactly as described in the first message in this thread.

No changes were made to zsh. I installed fzf, which added [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh to the end of .zshrc, but moving it elsewhere did not help.

An OSX security update package was installed, though.

I updated today pure with npm install --global pure-prompt, to no effect. The prompt works as expected outside of tmux. Any idea what might be wrong?

Here is the gist with .zshrc.

@srustamo srustamo reopened this Mar 30, 2016
@mafredri
Copy link
Collaborator

You have double entries of:

source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /usr/local/opt/zsh-history-substring-search/zsh-history-substring-search.zsh

Remove the ones that are before the bottom, also experiment with having them in different order.

Other than that, have you tried removing stuff from your zshrc until it works again, e.g. does removing the sourcing of .fzf.zsh help?

@srustamo
Copy link
Author

I keep .zshrc under git, and reverted to the version just before fzf related addition. So, I know that this revision was the one working (the changes before this revision irrelevant to this issue). Alas, the problem it seems is not related to .zshrc.

Playing with the order of last two lines did not help. Checked .tmux.conf revision history - no changes in the last 3 month.

Very confusing. The only major change which happened was the OSX security update. Reverting that would take a lot of effort.

@mafredri
Copy link
Collaborator

Did you also remove the duplicate lines sourcings of zsh syntax highlighting and zsh hss? You didn't mention it so I'm just confirming.

I realize that this config was working before, I was just suggesting that you could try to narrow down the issue and see if it's possible that any part of it is conflicting by removing / commenting parts and seeing if it starts working.

@mafredri
Copy link
Collaborator

Somehow I suspect this is due to something external. I can reproduce if I just use

PROMPT='%(?.%F{green}.%F{red})${${KEYMAP/vicmd/❮%f}/(main|viins)/❯}%f '

But the second I add:

function zle-line-init zle-keymap-select {
    zle .reset-prompt
}
zle -N zle-line-init
zle -N zle-keymap-select

The problem is gone.

@srustamo
Copy link
Author

It looks like I narrowed it down to .tmux.conf. If I remove it completely, and run tmux without it, there are no problems with the prompt. Would you mind having a look at .tmux.conf for any obvious issues?

@mafredri
Copy link
Collaborator

Nothing immediately sticks out, maybe this does something funky, or perhaps this (no idea what this does)?

PS. This is just a hunch, but would you mind doing a zsh --version both outside and inside tmux? Just wondering if you're using a different zsh inside the tmux.

@srustamo
Copy link
Author

The culprit is indeed this line set-option -g default-command "reattach-to-user-namespace -l zsh".

This is a wrapper for tmux accessing OSX system clipboard. I just remembered that it was updated a couple to days ago.

Commenting that line out restores the prompt char behaviour, but alas breaks the access from tmux to system clipboard.

If you don't mind, let me leave this issue open for a while, perhaps some OSX users can chime in.

@srustamo
Copy link
Author

FWIW, zsh --version in both cases is zsh 5.2 (x86_64-apple-darwin13.4.0).
which zsh in both cases is /usr/local/bin/zsh.

Many thanks for you time and support!

@srustamo
Copy link
Author

srustamo commented Apr 1, 2016

Here is a rather detailed analysis of a possible cause(s).

Perhaps it sheds some light?

@mafredri
Copy link
Collaborator

mafredri commented Apr 1, 2016

I believe ChrisJohnsen is correct in that the prompt is the wrong place to check for KEYMAP. Making this small change should alleviate your issues if that's all there's to it:

VIM_PROMPT=""
PROMPT='%(?.%F{green}.%F{red})${VIM_PROMPT}%f '

function zle-line-init zle-keymap-select { 
    VIM_PROMPT=${${KEYMAP/vicmd/❮}/(main|viins)/❯}
    zle .reset-prompt
}
zle -N zle-line-init
zle -N zle-keymap-select

Now the VIM_PROMPT parameter is only evaluated during zle-line-init and zle-keymap-select and is set to either or .

EDIT: Updated the code, realized there's no need to perform expansion, the substitution is enough.

@mafredri
Copy link
Collaborator

mafredri commented Apr 1, 2016

@srustamo from your comment on the issue over at tmux-MacOSX-pasteboard I take it this solved the issue (PS. did you notice I also updated the code in my post above).

I'll update the wiki to reflect this.

@mafredri mafredri closed this as completed Apr 1, 2016
@srustamo
Copy link
Author

srustamo commented Apr 1, 2016

Thank you!

mafredri added a commit to mafredri/pure that referenced this issue May 6, 2018
When merged, we can remove the VI-mode references from the Wiki.

Related: sindresorhus#308, sindresorhus#208, sindresorhus#184 and sindresorhus#98.
mafredri added a commit to mafredri/pure that referenced this issue May 8, 2018
When merged, we can remove the VI-mode references from the Wiki.

Related: sindresorhus#308, sindresorhus#208, sindresorhus#184 and sindresorhus#98.
mafredri added a commit to mafredri/pure that referenced this issue May 13, 2018
When merged, we can remove the VI-mode references from the Wiki.

Related: sindresorhus#308, sindresorhus#208, sindresorhus#184 and sindresorhus#98.
mafredri added a commit that referenced this issue Jul 30, 2018
* Add support for VI-mode indicator

Related: #308, #208, #184 and #98.

* Document VI-mode limitation (Zsh 5.3+)
kutsan pushed a commit to kutsan/pure that referenced this issue Jun 19, 2023
* Add support for VI-mode indicator

Related: sindresorhus#308, sindresorhus#208, sindresorhus#184 and sindresorhus#98.

* Document VI-mode limitation (Zsh 5.3+)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants