26.4.2 Moving in the Parenthesis Structure
The following commands move over groupings delimited by parentheses (or whatever else serves as delimiters in the language you are working with). They ignore strings and comments, including any parentheses within them, and also ignore parentheses that are quoted with an escape character. These commands are mainly intended for editing programs, but can be useful for editing any text containing parentheses. They are referred to internally as βlist commands" because in Lisp these groupings are lists.
These commands assume that the starting point is not inside a string or a comment. If you invoke them from inside a string or comment, the results are unreliable.
C-M-n
β
Move forward over a parenthetical group (forward-list
).
C-M-p
β
Move backward over a parenthetical group (backward-list
).
C-M-u
β
Move up in parenthesis structure (backward-up-list
).
C-M-d
β
Move down in parenthesis structure (down-list
).
The list commands C-M-n
(forward-list
) and C-M-p
(backward-list
) move forward or backward over one (or n
) parenthetical groupings.
C-M-n
and C-M-p
try to stay at the same level in the parenthesis structure. To move up one (or n
) levels, use C-M-u
(backward-up-list
). C-M-u
moves backward up past one unmatched opening delimiter. A positive argument serves as a repeat count; a negative argument reverses the direction of motion, so that the command moves forward and up one or more levels.
To move down in the parenthesis structure, use C-M-d
(down-list
). In Lisp mode, where β(
β is the only opening delimiter, this is nearly the same as searching for a β(
β. An argument specifies the number of levels to go down.