Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: mysterious newline



2026-11-20 06:04:53 -0700, Ray Andrews:
[...]
> Gotta learn these 'subscript flags'. Half the battle is
> knowing what various syntactic elements are even called.
> Googling for '(w)' isn't helpful. AI is getting useful tho, it
> says that 'substring qualifier' is correct, but I expect that
> 'subscript flag' is just as good.
[...]

There are certainly a lot of those single letter/character
flag-like things in zsh even more so than in other shells. A
quick inventory (likely not exhaustive):

- *options* for zsh itself and most of its builtins like for
  other commands. Sometimes also called "flags".
  Origin: 1970 Unix and likely earlier
  Learn with: info zsh <the-builtin>
  Example: "print -u2 -rC1 -- $elements" to print elements [r]aw
           on [1] [C]olumn and on [u]nit (fd) [2] (stderr).

- C style *escape sequences* as used in many places (in
  arguments to echo, print, printf, bindkey, inside $'...', etc)
  Origin: mid 70s, C language.
  Learn with: info zsh echo
  Example: "print 'foo\tbar\nbaz'" with \t for horizontal [t]abulation,
           \n for [n]ewline,
	   "cmd $'St\ue9phane'" for character of [u]nicode code
	   0xE9

- printf / print -f *format specifiers*
  Origin: mid 70s, printf() C function
  Learn with: info zsh printf
  Example: "printf '%o, %e\n'" 12+5 1./12" to [print] numbers
	   [f]ormattd in [o]ctal or [e]ngineering notations.

- *vi command mode key bindings* when the line editor is in
  vi mode (bindkey -v)
  Origin: late 70s
  Learn with: info zsh 'standard widgets'
              bindkey -M vicmd
  Example: "dw" to [d]elete a [w]ord

- *emacs key bindings* when the line editor is in emacs mode
  (bindkey -e)
  Origin: late 70s emacs
  Example: ^E to go to the [E]nd of the line

- *modifiers* used for history expansion, parameter expansion
  and in glob qualifiers
  Origin: late 70s in csh, also used in vim and bash (for
  history only there).
  Learn with: info zsh mofifiers
  Example: "cd -P -- $file:h" to cd to the [t]ail of $file,
           "!!:gs/foo/bar" to rerun the last command with
	   [foo] [s]ubstituted with [bar] [g]lobally.
	   "print -r -- $text:u" for [$text] in [u]ppercase

- prompt expansion *prompt escapes*, as used in prompt
  formatting ($PS{1,2,3,4}, $PROMPT{,2,3,4}, $RPS{1,2}, print
  -rP, % parameter expansion flag...)
  Origin: 1987 tcsh
  Learn with: info zsh 'prompt expansion'
  Example: "PS1='%B%~%b%% '" to show the working directory in
  [B]old.

- there are more (different) format specifiers for TIMEFMT,
  WATCHFMT, zformat...
  Learn with: "info zsh TIMEFMT", etc.

- *globbing qualifiers* to further qualify globs based on other
  critieria than just names. To me, that's the killer feature of
  zsh and one of the main reasons I wouldn't consider using any
  other shell until they have something similar
  Origin: 1990 zsh 1.0
  Learn with: info zsh qualifiers
  Example: print -rl -- *.txt(.m-7Om) to list the regular txt
  file last [m]odified within the last [7] days, reverse
  [O]rdered by [m]odification time.

- *parameter expansion flags*
  Origin: 1994 zsh 2.5 (I think)
  Learn with: info zsh flags
  Example: "print -rC1 -- ${(Ls[:])var}" to [s]plit $var on [:]
  and convert to [L]ower case.
  Some feature overlap with csh-style modifiers

- *globbing flags*
  Origin: 2000 zsh 3.1.7 (I think), inspired by perl regexp
  (?flags)
  Learn with: info zsh 'globbing flags'
  Example: "print -rl -- *.(#i)txt" to list files with txt
  extension case [i]nsensitively.

- *subscript flags*
  Origin: 2001 zsh 4.0.1
  Learn with: info zsh subscript
  Example: "echo $array[(I)pattern]" for the [I]ndex of the last
  element matching pattern.

info zsh something

Takes you to the first index or table of contents entry for
[something] or anything starting with [something].

The zsh manual has a very good index.

Within info, you press i to bring up a prompt for an index entry
where there is completion available.

So for instance, if you type "subscr<Tab><Tab>" that will first
complete to "subscript" and show a list of index entry
completions:

2 completions:
subscript flags    subscripts

So "info zsh subscript" actually takes you to the index entry
for "subscript flags".

You can search that index by pressing I (uppercase i, shift+i)

Then if you enter "flag", you'll see a list of all index entries
containing "flag".

Run "info info" for details (you used to get a tutorial there,
seems it's gone now in Debian and you only get a reference
manual instead).

To search for "w" specifically, best is to search (with / like
in ed/vi/less...) for " w " or the regexp: (^| )w( |$) to also
look for w at the start or end of a line. \<w\> will also bring
up all the -w options of the various builtins.

For man, the default pager is usually "less", you search with
"/" but beware the regexp flavour will depend on how less was
compiled. On GNU/Linux OSes, by default you generally get
GNU-style EREs, so you can look for "(^| )w( |$)" or "\<w\>" or
"^ *w\>" as well. If using perl-like regexps, you'd use \b in
place of \< or \> for word [b]oundaries.

-- 
Stephane




Messages sorted by: Reverse Date, Date, Thread, Author