Substitution modifiers can be applied to any command, variable or history substitution. Any number in a row can be applied.
| Operator | Meaning |
|---|---|
| :n |
nth word |
| :# |
Count the number of words |
| :^ |
Word number 1, counting from 0 |
| :$ |
Last word |
| :% |
Word matched by a !?str? history search |
| :n-m |
nth through mth words |
| :-n |
0 through nth words |
| :n- |
nth through next-to-last words |
| :n* |
nth through last word |
| :* |
1 through last word |
| :q |
Single-quote each word |
| :s/str1/str2/ |
Substitute str2 for str1 and then reparse into words. Match failures are considered to be errors unless ignoreerrors == 2. |
| :S/str1/str2/ |
Substitute str2 for str1 but leave it as a single string. Also, failure to match is not considered an error. |
| :& |
Repeat last substitution |
| :g |
Global editing: as a prefix character to any of the other editing operators, it means apply the edit operation everywhere it matches, not just the first occurrence. |
| :x |
Treat each word as a string, break it up into words, then single-quote each word. |
| :p |
Print the substitution but don't execute the statement. (Ignored except in history substitutions.) |
|
:h :r :t :e :f :m :M :A :L |
Pathname editing operators: head, root, tail, extension, fullpath, mixedpath, fullmixedpath, shortname and longname. |
Pathname editing
Variable substitutions
History recall
Command substitution
Tutorial: Editing
Tutorial: Variables
Tutorial: History
Tutorial: Command substitution