zsh: completion menu. How to place common part of names? - zsh

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.

Related

In R, if I want to bring down the previous command without overwriting what I've already written, how can I do this?

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!

Closing multiple iTerm2 tabs makes zsh_history lose most of the history

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.

zsh completion : suggestion of multiples directory and how to choose one without knowing the content of this directory

I have a simple issue with zsh. Sometimes, I am in a directory with multiples sub-directories.
So, when I do a $ ls[TAB] or $cd[TAB], I list all these sub-directories.
But how to accept one of the suggestions for sub-directories? Is there a short cut or a key to choose a directory to go deeper in this directory.
I must precise that I don't know systematically the content of these subdirectories, so I can't often choose a subdirectory in which the first letter of filename could allow me to choose automatically the sub-directory to explore.
I was looking for a solution on the web but documentation about zsh completion is pretty big.
Edit: simplest solution to accomplish the desired effect:
press [/] key to 'accept' the current suggested directory ; then press again [tab] key to show suggestions of its subdirectories
Old suggested solution:
Install https://ohmyz.sh/
Then pressing the [tab] key displays a list and the first item is highlighted.
Hit the [tab] key again to choose the desired item and hit the [enter] key to write it in the command line interface, without actually executing the command, only as if you have just typed it in.
Then you can continue hitting the [tab] key to select another subdirectory, and so on.
It also works on any autocompletable, not only dirs.
The only way I know is: double click your target + cmd c + cmd v and then press Enter.

Commands not executing on keybind, but are executing from command pallet

Got an issue with keymapping commands:
https://www.youtube.com/watch?v=d5nrEO_t7Wo
As you can see in the video, when I call the commands by keyboard shortcut:
On the first attempt - the function isn't called.
On the second attempt - the function is called.
Where as, when I call the commands via the command pallet, the commands are called even on the first attempt. Not shown in the video, I can call the commands from the command pallet more than once without fail.
This leeds me to believe there is something wrong with my keymap.coffee:
'.editor:not(.mini)':
'shift-cmd-h': 'hex:view'
'alt-down':'editor:add-selection-below'
'alt-up':'editor:add-selection-above'
'.editor':
'cmd-k':'jxa:compile'
'shift-cmd-k':'jxa:compileApp'
'cmd-u':'jxa:execute'
However I can see nothing clearly wrong here... So perhaps there's something wrong with my init.js?
https://github.com/sancarn/JXA-Compile/blob/master/src/init.js
Any ideas?
This was solved by DamnedScholar here.
Okay, no. It's because cmd-k is bound to so many things. Go into Settings -> Keybindings and search for it and you'll see a lot of different things attached to it that are all bindings with multiple key presses. So when you press cmd-k, Atom waits to see what your next key press will be. You should consider using something different for jxa:compile.

Oh my zsh - exclude widgets from completion results

I'm really like AUTOCD option in zsh but widget names make it less comfortable in use. The problem is when I'm e.g. in my home directory, type "down" and press Tab I would expect completion for "Downloads" but on the first place in auto-completion is "down-line-or-beginning-search". Downloads is on the second pace what cause that I have to press tab additionally twice. It makes this process not to much ergonomic.
Does anybody know how to exclude widget names from zsh auto-completion?
zstyle ':completion:*:*:-command-:*:*' ignored-patterns 'down-line-or-beginning-search'

Resources