Select code block in vim

To do the first:

  • Hit $ to go to the end of the lineover the {
  • Push v or V (depending on whether you want to select lines or not)
  • Push % (to jump to the matching bracket).

To select just the inner part, go inside the inner part and use the i{ directional modifier.

For example, to delete everything inside the current {…} block, type: di{.


  1. $ to jump to the end of the line you're on (to be over the opening brace)
    v to begin a selection (V for whole lines)
    % to jump to the matching brace.

  2. j to go down one line so your cursor is inside the braces you are trying to select
    v to begin a selection (V for whole lines)
    i{ select everything inside the braces


To expand on Caleb's answer just slightly, vi{ will select the "inside" of the code block. To include the "outside" of the code block, ie including the braces, use va{.

This won't include the while stanza though. To do that you can use o to move the cursor to the beginning of the selection, and then 0 to move the selection to the beginning of the line.