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.
Related
I know that pressing the up arrow key brings down the previous command in R. In doing so, however, it overwrites anything that has already been typed on the command line. So for instance, if I want to define an object using a long command I've just executed, I have to press the up-arrow then either click or navigate via arrow keys all the way back to the beginning of the command to add in my object_name <- [command I've just brought down].
Is there anyway to bring down the previous command to wherever my cursor is, rather than having it overwrite the entire command line?
Thanks in advance for your help!
I use zsh 5.8 (oh-my-zsh + my custom configs) with iTerm2.
I want every zsh instance to store the command to the history every time I type it and share the history with the others.
It basically works as I want, but the problem is, if I (manually) quit iTerm2 with multiple tabs open (e.g. so that I can recover those tabs after reboot), the zsh_history file loses most of its content and contains only the first N commands.
My guess is the zsh instances kind of compete with each other in the last moment.
HISTSIZE and SAVEHIST are set largely enough (10000000).
setopt prints:
alwaystoend
autocd
autopushd
noclobber
completeinword
extendedhistory
noflowcontrol
histexpiredupsfirst
histfcntllock
histignoredups
histignorespace
histverify
incappendhistory
interactive
interactivecomments
login
longlistjobs
monitor
promptsubst
pushdignoredups
pushdminus
sharehistory
shinstdin
zle
Is there any way I can prevent this from happening?
EDIT: After seeing the comment, I disabled inc_append_history, but it's happening again.
EDIT2: Disabled appendhistory as well, but still the same.
EDIT3: After manually unsetting histsavebycopy (i.e., nohistsavebycopy), looking good so far.
EDIT4: Since the last change (EDIT3), I've experienced zsh: corrupt history file once.
EDIT5: Lost some history even without the corrupt history file error.
I have a tmux session called test with several windows, one for each test file. I have another tmux session with vim and the tmuxify plugin. When I tap <f8>, my .vimrc file is programmed to send the <f7> key to the the left pane in window #0 like so:
nmap <buffer> <F8> :execute "silent !tmux send-keys -t test:0.left 'F7'" <bar>:redraw!<CR>
<f7> triggers the test to be run. Works well.
However, notice the test:0.left bit. I have window #0 hardcoded in there. If I want to run the tests in window #7, for example, I first have to swap it with window #0 and then run the test.
What I'd rather do is just send the <f7> key to whatever window in the test session is currently open.
Is there a way to do this?
I consulted ye olde manual. Solution:
test:.left
Leaving the window blank defaults to the current window.
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.
I have completion menu configured in my zsh. It works great, no problem.
Now I want to make my zsh act like that:
Let's say there are 3 files in a directory:
somefile_first
somefile_second
somefile_third
Now when I press [TAB], I get completion menu with the first file placed in the command line.
But I want zsh to complete the common part of file names (in this example it would be somefile_), do not place anything else after the common part, and let me navigate through completion menu.
How do I do that?
I realize this question is old but I stumbled upon it when looking for the same answer. Here is what I found out.
AFAIK when using completion menu zsh will always place highlighted completion in the command line. However you can make it less hasty.
unsetopt menucomplete
setopt automenu
Changes the behaviour so
first TAB completes the common part
second lists completions without changing command line
third starts the menu and completes command line with highlighted completion
If you prefer no command line changes than fancy menu unset automenu too:
unsetopt menucomplete automenu
That gives bash-like completion. Only common part is completed and propositions are listed.