How do I select an entire code block from opening brace to closing brace in visual mode?
V%
Pressing V% enters visual line mode on the current line and immediately extends the selection to the line containing the matching bracket or brace.
V%
Pressing V% enters visual line mode on the current line and immediately extends the selection to the line containing the matching bracket or brace.
+
The + command moves the cursor to the first non-blank character of the next line.
O (in blockwise visual mode)
In blockwise Visual mode (), pressing O moves the cursor to the diagonally opposite corner of the rectangle.
cx{motion} … cx{motion} (vim-exchange)
The vim-exchange plugin provides cx{motion} to mark a region, then cx{motion} again on a second region to swap them in place.
[/ and ]/
Vim provides two motions for navigating C-style block comments (/ .
[{ and ]}
The [{ motion jumps to the previous unmatched { — the opening brace of the block enclosing your cursor.
V]}
Pressing V]} in normal mode enters visual line mode and immediately extends the selection to the next unmatched closing brace }.
visual-mode #visual-mode #navigation #text-objects #editing #motions
packadd matchit
Vim ships with matchit.
d/{pattern}<CR>
Vim lets you use a / search as a motion for any operator.
=G
The =G command applies Vim's auto-indent operator (=) from the current line to the last line of the file (G).
n.
The n.
gwip
The gw operator reformats text just like gq, but leaves the cursor in its original position after reformatting.
[m
The [m motion jumps backward to the start of the nearest enclosing or preceding method definition.
[[
The [[ and ]] commands navigate between top-level code blocks — specifically, lines where { appears in column 1.
[[ and ]]
[[ and ]] navigate between section boundaries — typically the start of the previous or next top-level block.
:set iskeyword+=-
By default, Vim treats hyphens, dots, and many punctuation characters as word boundaries.
{count}<C-a> / {count}<C-x>
While increments and decrements a number by 1, you can prefix either with a count to add or subtract a specific amount.
v_o
When you start a visual selection, the cursor is at one end and the anchor is at the other.
[{ / ]}
When editing code inside a deeply nested block, [{ jumps backward to the unmatched { that encloses the current position, and ]} jumps forward to its matching }.
]m and [m
The ]m and [m motions let you jump forward and backward between the start of method or function definitions.