When switching panes in tmux using ^B and cursor keys, what is the quickest way to get out of pane-switching mode and return input handling to the program in the pane?
For instance, you just switched to the shell in your left pane with ^B and Left, and now you want to press Up and Enter to repeat the shell's last command, except tmux steals the Up keypress thinking you're still switching panes.
There has to be a key combo or something to finish pane switching, right?
because pressing arrows is "expensive" keystroke with my keyboard, I hardly use arrow keys.
My vim has ctrl-h,j,kl to switch windows, so I defined in tmux prefix h,j,k,l to switch panes. (my prefix is ctrl-a)
For commandline editing, I don't use any arrow keys either, instead, I use ctrl/alt heavily, my ctrl key is at a good position to press. so re-run last command, I press ctrl-p, enter.
Using ctrl/alt to edit commandline is fast and convenient, since you don't leave your home row.
ctrl-p last cmd
ctrl-h backspace
ctrl-a first col
ctrl-d del current char
ctrl-e eol
ctrl-w remove word backwards
ctrl-b/f back/forward
alt-b/f back/forward a word
alt-d remove word forward
there are a lot more... like ctrl-k, ctrl-u, ctrl-y, alt-. etc.
And if I need edit a really long and complex command, I do ctrl-x ctrl-e, and edit it in my vim.
Related
In basic iterm2, multi-select is simple, just hold command key and drag-and-drop or double click will do the trick. We will have some discrete highlight text, something like this:
i.e. I can have "At work" & "inversel" highlight at the same time.
But this does not work in tmux session with iterm2, hold command key and drag-and-drop will not select anything or highlight.
Thanks for any suggestions.
EDIT:
A million thanks to #Simba for the detailed explanation. But I can't find the "mouse report" switch, is this about the item2 version or I miss something?
EDIT2:
#Simba I found the box (Session -> Edit Session -> Terminal -> Enable mouse reporting), but uncheck it's not working, even after I restart itemr2 it's checked again everytime LOL
EDIT3:
After several times restart now it's working, I have no idea what's happening... Thanks! #Simba
"hold command key and drag-and-drop" to do multiple copy is a feature of iTerm2, the terminal. Within tmux, the copy action is handled by tmux, and tmux doesn't support this multi-copy feature.
Method 1
An alternative way: use tmux integration mode of iTerm2 by starting a tmux session with tmux -CC.
After this, the drag action is detected by iTerm2 directly. You can copy the content in iTerm2 by holding "Command" just as when tmux is not used.
Method 2
Cmd + Drag is bound to continuous selection in iTerm2. Since "mouse reporting" is intercepted by tmux, to use this feature (continuous selection), you need to disable "mouse reporting" temporarily.
Uncheck "Session -> Terminal State -> Mouse reporting".
Do continuous selection with Cmd + Drag.
Enable "Mouse reporting" to make tmux work properly.
Drawback: To use continuous selection, "Mouse reporting" must be disabled. But once "mouse reporting" is disabled, you can't scroll to previous or next page. That means you can do continuous selection in current page.
Quote from iTerm2 FAQ
Q: What modifier keys affect marking a selection for copy and paste?
A: If you hold down modifier keys while making a selection, the behavior changes in various ways:
Alt/Option: Mouse reporting will be disabled. If you're using vim and you can't make a selection, try holding down the alt key and see if that fixes it.
Alt + Cmd: Make a rectangular selection.
Shift: Extend an existing selection.
Alt + Shift: Extend a rectangular selection.
Cmd: Make a discontinuous selection
Unfortunately, selection modifier key Alt + Cmd is bound to " rectangular selection" and it doesn't seem to be customizable. But you can bind a shortcut to toggle "mouse reporting".
I want to create a tmux keybind which sends a set of keystrokes to the marked pane. This is convenient for implementing a hotkey that runs something so I don't have to manually focus another pane and then come back.
But I'd like for this key to not do anything if there's no marked pane present. I've looked in the manpage and found nothing obvious that I can use to check this state.
To target the marked pane you can use -t '~' or -t '{marked}'.
In this case it is simply a matter of send -t '~' <keys here>.
A more generic way to get the marked pane in your shell would be tmux display -p -t '~' '#D'.
When a command is executed, the command is saved to history. Is there an option in zsh which automatically save the commands interrupted by Ctrl-C to history?
If you mainly want to put a command back and run another first, I would suggest using the push-line widget, which is made just for that. It puts the current command on hold and clears the command line. After running another command, the original command is automatically restored. If you want to run multiple commands, you can repeat the process. As it works on a stack, you can even put multiple commands on hold. They will be restored in reverse order.
From the zshzle(1) manpage:
push-line (^Q ESC-Q ESC-q) (unbound) (unbound)
Push the current buffer onto the buffer stack and clear the buffer. Next time the editor starts up, the buffer will be popped off the top of the buffer stack and loaded into the editing buffer.
As you can see, by default it is bound in emacs mode (bindkey -e) to ^[q, ^[Q and ^Q. That is Alt+q (or Esc, q), Alt+Shift+q (or Esc, Shift+q) and Ctrl+q. The last of which only works if the option FLOW_CONTROL is disabled (setopt noflowcontrol).
There is also the push-line-or-edit widget. It behaves the same on a primary (PS1) prompt. But on a secondary (PS2) prompt it makes the whole multi-line construct (not just the current line) editable. Just like when you pull a multi-line construct from history.
I know the prompt changes from < to + when the command line in R expects you to complete the current command. Is there a way (say, shortcut key) to immediately terminate the command being written and revert from the '+' mode to the regular console '>'?
Press 'Esc' key will bring you back to the prompt (<). You don't need to type word 'Esc'.
I suspect you are using a usb keyboard that has chromatic color controls via software. It sometimes mess up the keys therefore simply do a factory reset of your keyboard via install software. Then pressing "Esc" will revert to the
"greater than sign"
My .zshrc file contains the line
bindkey -v
I'm attempting to bind ^q or \M-q to push-line, e.g.
bindkey "^q" push-line
but for some reason it isn't working.
Running `bind key -v' confirms
"^Q" push-line
But it doesn't actually do anything. Other control- mappings, such as ^r, work fine.
I can successfully map "push-line" to "\eq", but I don't like this behavior. First of all, I never use esc- type bindings, and secondly doing so binds it to control, meta, and escape, which is overkill. (Incidentally, shouldn't it only bind all of them like that with `bindkey -m'? I never set that in my .zshrc?)
So, anybody have any idea what's going on here?
These shortcuts are used by Software flow control (wikipedia)
Ctrl+S and Ctrl+Q are used to stop and resume the output of a program.
To try it:
Run while (true) ; do echo $RANDOM ; sleep 1 ; done
Press Ctrl+S, the output stop.
Press Ctrl+Q, the output resume.
(I'm not sure the program is stopped like with Ctrl+Z, i think it is stuck by lack of outputting. Ctrl+C to kill the program.)
These shortcuts take over your shortcuts, but if you disable this flow control feature, it could work.
You can learn how to disable it in How to unfreeze after accidentally pressing Ctrl-S in a terminal? - Unix and Linux.
Try it and tell us.