ToDo
*(-OL[1,3])
gives a list of the names of the three largest files.
Misc
# Like ^O in emacs modes (accept-line-and-down-history). # Binding it in menuselect mode means it no effect on ^O in the normal keymaps. # Try it out by entering menu selection on a set of files including # directories, and typing ^O on one of the directories. You should # immediately have the contents of that directory presented for the # next selection, while undo is smart enough not only to remove that # selection but return to completion on the parent directory. bindkey -M menuselect '^o' accept-and-infer-next-history
Alt-Q
- Type something
- But you want to run some other command first before this one.
<ESC>-<CR>
inserts a literal newline so you can create multi line commands at the prompt easily.- Type Alt-Q
- You now have a fresh prompt
- Run that other command.
- Your prompt automatically gets populated with what you had when hitting Alt-Q
<C-X>e
Let's you edit the current command line in your favorite editor.
autoload edit-command-line
zle -N edit-command-line
bindkey '^xe' edit-command-line
Quote entire line
Type <ESC>-'
to quote the currently entered line. Useful
if you want to pass it to su -c
, python -c
, etc.
Path to command
Prepend with =
. e.g. =ls
expands to /bin/ls
.
***
expands like **
but follows symlinks
Glob numbers
ll -d ~/ck/vcs/ck<2-5> # drwxr-x--- 5 chirayu eng 4.0K Feb 24 2011 /home/chirayu/ck/vcs/ck2 # drwxr-x--- 16 chirayu eng 4.0K Feb 4 12:30 /home/chirayu/ck/vcs/ck5
Autoquoting URLs
Ever pasted an URL into your command line, only to discover that you need to quote all those weird characters? Luckily we have computers to do our bidding:
autoload -U url-quote-magic zle -N self-insert url-quote-magic
cd
to alternate path
From: zshwiki: cd
if you are at ~/data/foo/horrible/dir/names
and want to go to ~/data/bar/horrible/dir/names
, just do:
% pwd ~/data/foo/horrible/dir/names % cd foo bar % pwd ~/data/bar/horrible/dir/names
What's even better is that cd foo [TAB]
will complete with bar!!
Aliases with trailing spaces
A trailing space causes the next word to be checked for alias expansion
# Suppose you had this alias. alias foo='ls -l' # Now define an alias with a trailing space. alias nop='echo ' # trailing space to alias expand the next word
Now if you run nop foo x y
, it is expanded to
echo ls -l x y
.
Meta queries
^Xh
– What is the completion context?
Use ^Xh
at the command line to get the completion context at the
cursor.
e.g. If you typed print $_comps[
and press ^Xh
, you will see
something like:
tags in context :completion::complete:-subscript-:: association-keys (_subscript (eval))