How to multi-select text block in iterm2 with tmux? - tmux

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".

Related

Changing the acceptance key (autosuggest-accept) - ZSH shell on mac

on > zsh mac terminal
if i type c and get the autocompletion suggestion as clear
To accept that suggestion i need to hit right arrow key and then press enter to run it.
I want to change the right arrow key to something else for example ` OR '
Plese help on finding a way to change this behaviour.
You can change bindkey for autosuggest-accept widget.
bindkey '`' autosuggest-accept
Note that this will disable your ability to type ` character directly though.
If you want to execute the autosuggest immediately after hitting `, change autosuggest-accept to autosuggest-execute.
To make this change permanent, add the bindkey line to your ~/.zshrc
If you also want to disable arrow key, you can remove the widget from ZSH_AUTOSUGGEST_ACCEPT_WIDGETS array.
ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=("${(#)ZSH_AUTOSUGGEST_ACCEPT_WIDGETS:#forward-char}")
As a more out-of-the-box solution, I just found out here that you can use:
CTRL+E
instead of the right arrow, and it will accept the autosuggestion.
In the link they refer to it as "end-of-line in emacs mode", but I didn't configure anything of the sort, so I guess it just works.

How to use the Edit/add new keyboard shortcuts in Jupyter

I am in the Edit Command mode Shortcuts dialog and things seem reasonable ..
But the actual behavior is a different story
When using the Option modifier (plus a non-modifier key) it just ends up printing a high-ascii character value in the add shortcut area .. and then when I refresh the page it has gone away.
I can not get Command modifier (plus a non-modifier key) to work at all. It is jus ignored.
The Control modifier (plus any key) is completely ignored.
So there is a basic usability misunderstanding here. Advice appreciated.
I added 'Ctrl-Q' as a shortcut to restart kernel and run all the cells. You can see the picture below. It is working fine. In the 'Ctrl-Q', 'Q' was just lowercase and it ran successfully.

Efficient pane switching in tmux

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.

How to set user command in Qt Fakevim?

(1) For example, I want to set map gd g* in Qt's Fakevim like below but failed.
(2) And also I'd like to set F3 as the save command, how to do it?
(3) In Fakevim, it provides an option "Read .vimrc", but where to find the file .vimrc?
Thank you!
It doesn't look like there is a lot of documentation for FakeVim, so official sources might not exist. Most of this was obtained by experimentation.
If you want to dig deeper, I guess there's no source as official as the actual source: http://qt.gitorious.org/qt-creator/qt-creator/blobs/0809986e501415fe2c8508800b94b5b3169dc048/src/plugins/fakevim/fakevimplugin.cpp
User commands
First off, realize that in Tools>Options>FakeVim>User Command Mapping, you're only setting what your user actions will perform, not how you perform them.
By default, user command #1 is triggered by pressing Alt-V, then 1.
Alt-V, then 2, triggers user action #2, and so on.
You can change the keyboard shortcuts through the general QtCreator configuration interface, under Tools>Options>Environment>Keyboard. There is a "FakeVim" section with all the user actions listed. Select your user action of choice, press the little "erase" icon in the input field under "Shortcut", then press your desired shortcut key, which should appear in the input field.
Second, to finish a command where you would normally press enter, you should literally type in <CR> after the commands. You also need to enter in ':' to enter command mode.
So if you wanted to map the vim save command, ":w", to F3 via FakeVim, you would:
Go to Tools>Options>FakeVim>User Command Mapping.
Enter ":w<CR>" as one of the user commands (say #7).
Go to Tools>Options>Environment>Keyboard.
Find the FakeVim action "UserAction7".
Set F3 as a shortcut for it.
Now, every time you're in the editor, you should be able to click F3 and have the FakeVim :w command execute, which will save your file.
Note that there is also an option to set a shortcut for "Save" directly in the QtCreator keyboard settings, so for this particular shortcut you don't actually need to go through FakeVim.
Setting shortcuts for other vim commands should be similar. Note that you're restricted to the subset of vim commands that FakeVim implements. Refer to the source, linked above, for checking any particular command you're wondering about.
Vimrc file
On Linux this would be ~/.vimrc, a file in the user's home directory. I presume you're asking about Windows.
The best source I can find is this bug report about it being hard to use Fakevim's vimrc on Windows: https://bugreports.qt.io/browse/QTCREATORBUG-8748
Following that, the file Fakevim looks for is ".vimrc" in %USERPROFILE% (you can enter a name like that in Explorer to go to the folder). However, it's tricky to access a file with a name like that on Windows. (Thus why the real vim uses '_vimrc' on Windows -- but FakeVim apparently doesn't, at least at the moment.)
Here is a superuser page with workarounds for how to create such files on Windows: https://superuser.com/questions/64471/create-rename-a-file-folder-that-begins-with-a-dot-in-windows

zsh: Unable to bind ^q or \M-q in vi mode

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.

Resources