2

I just recently switched to using bash vi mode with set -o vi setting in my .bash_profile. But this leads a problem

I had a tmux mapping that would run the clear-history command when I pressed <ctrl>+k. This was the relevant mapping

bind -n C-k clear-history

This does not work in bash vi mode, probably because vi mode takes precedence. How do I resolve or work around this issue?

Curious
  • 20,870
  • 8
  • 61
  • 146

2 Answers2

2

You could change the key, this is what I use:

# reset & clear history
bind r send-keys -R \; send-keys C-l \; clear-history 

You have to press ctrl+b+r

k can indeed be used but if you also move across panels (ctrl + hkjl), it may become confusing.

In any case this work by just using ctrl+k

bind -n C-k send-keys C-l \; run-shell "sleep .3s; tmux clear-history"

Without using the sleep:

bind -n C-k send-keys -R \; send-keys C-l \; clear-history
nbari
  • 25,603
  • 10
  • 76
  • 131
  • This doesn't work for me , it doesn't clear history. I can scroll through history still with `+b [` – Curious Oct 08 '17 at 16:15
  • the mappings of to use `r` instead of `k` ? – nbari Oct 08 '17 at 16:17
  • Didn't quite get that, what do you mean? I copied what you had in your answer and pasted it in my `.tmux.conf` and its clearing screen but not history, since I can scroll back through it even after pressing it – Curious Oct 08 '17 at 16:19
  • I think it's just executing `C-l` and not the `clear-history` after that – Curious Oct 08 '17 at 16:20
  • I upvoted your answer but I sort of don't want to use a solution that uses sleep.. Any other option? – Curious Oct 08 '17 at 16:36
  • 1
    I updated the answer, give a try ( interesting issue by the way) – nbari Oct 08 '17 at 16:44
  • Hmmm any way I can enter a configuration in the `inputrc` that sends a command to the attached tmux shell pane? – Curious Oct 08 '17 at 16:56
  • Hope this could help: http://minimul.com/increased-developer-productivity-with-tmux-part-5.html – nbari Oct 08 '17 at 17:04
0

From this question, I have the following tmux mapping:

bind-key -n C-k send-keys -R \; send-keys Escape C-l a \; clear-history

There are many variants of this (each with pros and cons, and for different use cases); see the linked question.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324