Next: , Up: C Modes


31.11.1 C Mode Motion Commands

This section describes commands for moving point, in C mode and related modes.

M-x c-beginning-of-defun
M-x c-end-of-defun
Move point to the beginning or end of the current function or top-level definition. These are found by searching for the least enclosing braces. (By contrast, beginning-of-defun and end-of-defun search for braces in column zero.) If you are editing code where the opening brace of a function isn't placed in column zero, you may wish to bind C-M-a and C-M-e to these commands. See Moving by Defuns.
C-c C-u
Move point back to the containing preprocessor conditional, leaving the mark behind. A prefix argument acts as a repeat count. With a negative argument, move point forward to the end of the containing preprocessor conditional.

#elif’ is equivalent to ‘#else’ followed by ‘#if’, so the function will stop at a ‘#elif’ when going backward, but not when going forward.

C-c C-p
Move point back over a preprocessor conditional, leaving the mark behind. A prefix argument acts as a repeat count. With a negative argument, move forward.
C-c C-n
Move point forward across a preprocessor conditional, leaving the mark behind. A prefix argument acts as a repeat count. With a negative argument, move backward.
M-a
Move point to the beginning of the innermost C statement (c-beginning-of-statement). If point is already at the beginning of a statement, move to the beginning of the preceding statement. With prefix argument n, move back n − 1 statements.

In comments or in strings which span more than one line, this command moves by sentences instead of statements.

M-e
Move point to the end of the innermost C statement or sentence; like M-a except that it moves in the other direction (c-end-of-statement).
M-x c-backward-into-nomenclature
Move point backward to beginning of a C++ nomenclature section or word. With prefix argument n, move n times. If n is negative, move forward. C++ nomenclature means a symbol name in the style of NamingSymbolsWithMixedCaseAndNoUnderlines; each capital letter begins a section or word. Rather than this command, you might well prefer the newer “Subword Mode”, which does the same thing better. See Other C Commands.

In the GNU project, we recommend using underscores to separate words within an identifier in C or C++, rather than using case distinctions.

M-x c-forward-into-nomenclature
Move point forward to end of a C++ nomenclature section or word. With prefix argument n, move n times.