How does one override an existing zsh keyboard completion?
Most likely, your system is using the newer compsys
system rather than the older compctl
system. See man zshcompsys
and man zshcompwid
(and man zshcompctl
).
The completion function for yast2
is probably in this file (or similar path):
/usr/share/zsh/functions/Completion/Linux/_yast
ZSH: How to disable default completion for `make`?
You need to set your fpath
. See here.
In your ~/.zshrc
, something like:
fpath=( ~/.zshfunctions $fpath )
where ~/.zshfunctions
contains your custom completion files, should solve this for you. Note that your functions are loaded before the system ones. This will not work:
fpath=( $fpath ~/.zshfunctions )
As an aside, you're using compctl
. It's old. I'd recommend using compsys
instead, although a decent link explaining why escapes me at the moment.
These go into some detail about writing completion functions, including the fpath
. You might find them useful for reference.
- Z-shell completion functions: introduction
- Writing z-shell completion functions
When using tab completion what is the fastest way to end your line of code?
I think you might like the AutoSemiColon plugin.
But a shortcut to move to the end of line is useful in many cases, so i suggest you put it your keymap file anyway. To prevent you from looking it up, here's the line:
{ "keys": ["ctrl+e"], "command": "move_to", "args": {"to": "eol", "extend": false} },
Fix key settings (Home/End/Insert/Delete) in .zshrc when running Zsh in Terminator Terminal Emulator
To know the code of a key, execute cat
, press enter, press the key, then Ctrl+C.
For me, Home
sends ^[[H
and End
^[[F
, so i can put i my .zshrc
in my home dir
bindkey "^[[H" beginning-of-line
bindkey "^[[F" end-of-line
bindkey "^[[3~" delete-char
These codes could change with the terminal emulator you use.
autoload zkbd ; zkbd
will create a file with an array of keycodes to use, like bindkey "${key[Home]}" beginning-of-line
, and you can source a different file depending on the terminal.
Zsh zle shift selection
shift-arrow() {
((REGION_ACTIVE)) || zle set-mark-command
zle $1
}
shift-left() shift-arrow backward-char
shift-right() shift-arrow forward-char
shift-up() shift-arrow up-line-or-history
shift-down() shift-arrow down-line-or-history
zle -N shift-left
zle -N shift-right
zle -N shift-up
zle -N shift-down
bindkey $terminfo[kLFT] shift-left
bindkey $terminfo[kRIT] shift-right
bindkey $terminfo[kri] shift-up
bindkey $terminfo[kind] shift-down
That assumes your terminal sends a different escape sequence upon Shift-Arrows from the one sent upon Arrow and that your terminfo database is properly populated with corresponding kLFT and kRIT capabilities, and that you're using emacs style key binding.
Or, to factorize the code a bit:
shift-arrow() {
((REGION_ACTIVE)) || zle set-mark-command
zle $1
}
for key kcap seq widget (
left LFT $'\e[1;2D' backward-char
right RIT $'\e[1;2C' forward-char
up ri $'\e[1;2A' up-line-or-history
down ind $'\e[1;2B' down-line-or-history
) {
functions[shift-$key]="shift-arrow $widget"
zle -N shift-$key
bindkey ${terminfo[k$kcap]-$seq} shift-$key
}
Above, hardcoded sequences for cases where the terminfo database doesn't have the information (using xterm
sequences).
Looking for ALT+LeftArrowKey solution in zsh
Run cat
then press keys to see the codes your shortcut send.
(Press Ctrl+C to kill the cat
when you're done.)
For me, (ubuntu, konsole, xterm) pressing Alt+← sends ^[[1;3D
, so i would put in my .zshrc
bindkey "^[[1;3C" forward-word
bindkey "^[[1;3D" backward-word
(Actually I prefer to use Ctrl + arrow to move word by word, like in a normal textbox under windows or linux gui.)
Related question: Fix key settings (Home/End/Insert/Delete) in .zshrc when running Zsh in Terminator Terminal Emulator
zsh equivalent of bash show-all-if-ambiguous?
Zsh has a lot of completion-related options (see man zshoptions
under Completion
). I think you're after setopt no_auto_menu
and perhaps setopt bash_auto_list
as well.
List of zsh bindkey commands
Commands available for use in the line editor are referred to as widgets. The standard widgets are listed in the zshzle
manpage in the STANDARD WIDGETS
section. That manpage is also available from the zsh website
Mac Terminal Auto Complete
Put this in your ~/.inputrc
:
set show-all-if-ambiguous on
You'll need to restart your shell (for example by opening a new terminal window or typing exec /bin/bash
).
Home/End keys in zsh don't work with putty
I found it's a combination:
One
The ZSH developers do not think that ZSH should define the actions of the Home, End, Del, ... keys.
Debian and Ubuntu fix this by defining the normal actions the average user would expect in the global /etc/zsh/zshrc
file. Following the relevant code (it is the same on Debian and Ubuntu):
if [[ "$TERM" != emacs ]]; then
[[ -z "$terminfo[kdch1]" ]] || bindkey -M emacs "$terminfo[kdch1]" delete-char
[[ -z "$terminfo[khome]" ]] || bindkey -M emacs "$terminfo[khome]" beginning-of-line
[[ -z "$terminfo[kend]" ]] || bindkey -M emacs "$terminfo[kend]" end-of-line
[[ -z "$terminfo[kich1]" ]] || bindkey -M emacs "$terminfo[kich1]" overwrite-mode
[[ -z "$terminfo[kdch1]" ]] || bindkey -M vicmd "$terminfo[kdch1]" vi-delete-char
[[ -z "$terminfo[khome]" ]] || bindkey -M vicmd "$terminfo[khome]" vi-beginning-of-line
[[ -z "$terminfo[kend]" ]] || bindkey -M vicmd "$terminfo[kend]" vi-end-of-line
[[ -z "$terminfo[kich1]" ]] || bindkey -M vicmd "$terminfo[kich1]" overwrite-mode
[[ -z "$terminfo[cuu1]" ]] || bindkey -M viins "$terminfo[cuu1]" vi-up-line-or-history
[[ -z "$terminfo[cuf1]" ]] || bindkey -M viins "$terminfo[cuf1]" vi-forward-char
[[ -z "$terminfo[kcuu1]" ]] || bindkey -M viins "$terminfo[kcuu1]" vi-up-line-or-history
[[ -z "$terminfo[kcud1]" ]] || bindkey -M viins "$terminfo[kcud1]" vi-down-line-or-history
[[ -z "$terminfo[kcuf1]" ]] || bindkey -M viins "$terminfo[kcuf1]" vi-forward-char
[[ -z "$terminfo[kcub1]" ]] || bindkey -M viins "$terminfo[kcub1]" vi-backward-char
# ncurses fogyatekos
[[ "$terminfo[kcuu1]" == "^[O"* ]] && bindkey -M viins "${terminfo[kcuu1]/O/[}" vi-up-line-or-history
[[ "$terminfo[kcud1]" == "^[O"* ]] && bindkey -M viins "${terminfo[kcud1]/O/[}" vi-down-line-or-history
[[ "$terminfo[kcuf1]" == "^[O"* ]] && bindkey -M viins "${terminfo[kcuf1]/O/[}" vi-forward-char
[[ "$terminfo[kcub1]" == "^[O"* ]] && bindkey -M viins "${terminfo[kcub1]/O/[}" vi-backward-char
[[ "$terminfo[khome]" == "^[O"* ]] && bindkey -M viins "${terminfo[khome]/O/[}" beginning-of-line
[[ "$terminfo[kend]" == "^[O"* ]] && bindkey -M viins "${terminfo[kend]/O/[}" end-of-line
[[ "$terminfo[khome]" == "^[O"* ]] && bindkey -M emacs "${terminfo[khome]/O/[}" beginning-of-line
[[ "$terminfo[kend]" == "^[O"* ]] && bindkey -M emacs "${terminfo[kend]/O/[}" end-of-line
fi
So, if you are connecting to a Debian or Ubuntu box, you don't have to do anything. Everything should work automagically (if not, see below).
But... if you are connecting to another box (e.g. FreeBSD), there might be no user friendly default zshrc
. The solution is of course to add the lines from the Debian/Ubuntu zshrc
to your own .zshrc
.
Two
Putty sends xterm
as terminal type to the remote host. But messes up somewhere and doesn't send the correct control codes for Home, End, ... that one would expect from an xterm
. Or an xterm
terminal isn't expected to send those or whatever... (Del key does work in xterm
however, if you configure it in ZSH). Also notice that your Numpad-keys act funny in Vim for example with xterm
terminal.
The solution is to configure Putty to send another terminal type. I've tried xterm-color
and linux
. xterm-color
fixed the Home/End problem, but the Numpad was still funny. Setting it to linux
fixed both problems.
You can set terminal type in Putty under Connection -> Data. Do not be tempted to set your terminal type in your .zshrc
with export TERM=linux
, that is just wrong. The terminal type should be specified by your terminal app. So that if, for example, you connect from a Mac box with a Mac SSH client it can set it's own terminal type.
Notice that TERM specifies your terminal type and has nothing to do with the host you are connecting to. I can set my terminal type to linux
in Putty and connect to FreeBSD servers without problems.
So, fix both these things and you should be fine :)
Related Topics
What Is The Linux Equivalent of Kernel32.Dll
Split Tar.Bz2 File and Extract Each Individually
How to Get a Process Tree Trace/Log of a Process in Linux
Process Scheduling from Processor Point of View
How to Reset Tty After Exec-Ed Program Crashes
Add a Directory When Creating Tar Archive
Qfiledialog: How to Filter Only Executables (Under Linux)
Amazon Ses on Google Cloud Computing Instance Vm Using Postfix
How to Get "Instant" Output of "Tail -F" as Input
Difference Between Posix Reliable Signals and Posix Real-Time Signals in Linux
PHPmyadmin Mcrypt Extension Is Missing
Shell Script to Shutdown/Restart Linux System
Trying to Install Docker Gpg Key Recieving Error: Curl: Option '-' Is Unknown
How to Configure Multiple Ssh Access to an Ec2 Instance
Make Diff to Ignore Symbolic Link