Top of a code block

Here is a command that I don’t use often but when I use it, I’m glad I have access to it.

[{ - go to [count] previous unmatched {

When editing code, I sometimes find myself in the middle of a gigantic code block and want to know what conditional or loop led me there. This command does exactly that. It scans backward for the previous unmatched curly brace and moves the cursor there.

Example:

1.   if (bar < 5) {
2.     baz();
3.   } else if (bar >= 13) {
4.     vector<int> nort = {1,1,2,3,5,8};
--     // 100 lines of C++ code
105.   baz();
106. }

Lets say my cursor is on line 105 and I can’t remember what branch of the conditional I’m on. If I input [{, the cursor will jump to the open curly brace on line 20. It skips the curley braces on line 6 because they match each other. It also skips any matched curley braces in the omitted block, regardless of if they are on the same line.

I hope you find this useful.

Written on January 16, 2016