To complement my previous article on ZSH FZF completion I've discovered very unknown features of Zle which should be worthy of mention.
Have you ever tried to paste a URL with ?
in it directly to a
wget
or curl
command? Most probably you've recieved a
No matches found
error because ?
is interpreted as a
special character by most shells, including ZSH. Most people's workaround for
this is to quote the URL with single or double quotes. Another workaround is
prepending \
to every special character such as ?
in
the URL.
Well I have good news for you. Someone has already taken care of this problem for you. The solution is called url-quote-magic
. Just add the following lines to your .zshrc
and you are good to go:
On my installation it is more thoroughly explained in the comments at the top
of the file: /usr/share/zsh/functions/Zle/url-quote-magic
I don't know about you, but since I use Neovim as my main text editor, I chose
to bindkey -v
and sync my vim key mappings with their equivalents
in ZSH's built-in Zle functions.
A well known concept in Vim's text editing are text objects. For example the
text between a set of brackets or parenthesis is called a text object. If this
information is not new to you and you use Vim, you may appreciate the following
addition to your .zshrc
:
autoload -U select-bracketed
zle -N select-bracketed
for m in visual viopp; do
for c in {a,i}${(s..)^:-'()[]{}<>bB'}; do
bindkey -M $m $c select-bracketed
done
done
This snippet was taken from a file called select-bracketed
found
in the same directory as url-quote-magic
(/usr/share/zsh/functions/Zle/select-bracketed
on my ZSH installation).
Just like with the above new bindings, the same was written for quotes such as `
, '
and "
. Try add the following from /usr/share/zsh/functions/Zle/select-quoted
:
autoload -U select-quoted
zle -N select-quoted
for m in visual viopp; do
for c in {a,i}{\',\",\`}; do
bindkey -M $m $c select-quoted
done
done
I hope you'll enjoy these little tweaks, I was really excited to find them out while inspecting the files that got shipped with my ZSH distribution here on Arch Linux.