Home Explore Blog CI



neovim

18th chunk of `runtime/doc/motion.txt`
17c88b515187f1e018818c4c5eac146b824286f0d23647440000000100000846
 around
			matches.

			No count is allowed, {count}% jumps to a line {count}
			percentage down the file |N%|.  Using '%' on
			#if/#else/#endif makes the movement linewise.

						*[(*
[(			Go to [count] previous unmatched '('.
			|exclusive| motion.

						*[{*
[{			Go to [count] previous unmatched '{'.
			|exclusive| motion.

						*])*
])			Go to [count] next unmatched ')'.
			|exclusive| motion.

						*]}*
]}			Go to [count] next unmatched '}'.
			|exclusive| motion.

The above four commands can be used to go to the start or end of the current
code block.  It is like doing "%" on the "(", ")", "{" or "}" at the other
end of the code block, but you can do this from anywhere in the code block.
Very useful for C programs.  Example: When standing on "case x:", `[{` will
bring you back to the switch statement.

						*]m*
]m			Go to [count] next start of a method (for Java or
			similar structured language).  When not before the
			start of a method, jump to the start or end of the
			class.  |exclusive| motion.
						*]M*
]M			Go to [count] next end of a method (for Java or
			similar structured language).  When not before the end
			of a method, jump to the start or end of the class.
			|exclusive| motion.
						*[m*
[m			Go to [count] previous start of a method (for Java or
			similar structured language).  When not after the
			start of a method, jump to the start or end of the
			class.  When no '{' is found before the cursor this is
			an error. |exclusive| motion.
						*[M*
[M			Go to [count] previous end of a method (for Java or
			similar structured language).  When not after the
			end of a method, jump to the start or end of the
			class.  When no '}' is found before the cursor this is
			an error. |exclusive| motion.

The above two commands assume that the file contains a class with methods.
The class definition is surrounded in '{' and '}'.  Each method in the class
is also surrounded with '{' and '}'.  This applies to the Java language.  The
file looks like this: >

	// comment
	class foo {
		int method_one() {
			body_one();
		}
		int method_two() {
			body_two();

Title: Vim Motions for Code Blocks and Methods
Summary
This section describes Vim motions for navigating code blocks and methods, particularly in languages like Java. It covers '[(' , '[{', '])', and ']}' for moving between unmatched parentheses or braces, ']m' and ']M' for jumping to the next start or end of a method, and '[m' and '[M' for jumping to the previous start or end of a method. These commands are useful for moving around code blocks, especially in C-like languages, and for navigating methods within classes in Java-like languages.