Vim Section Navigation

Normally #Vim uses easy to remember mnemonics like d2w (delete two words).
But when it comes to section navigation using ‘[[‘, ‘]]’, ‘[]’, and ‘][‘ it looks weired.
At least if you expect, that the opening and closing brackets are somehow matching opening
and closing braces.

(In C like languages function scopes {…} are sections so you can easily jump
to the next or previous function.)

I tried to figure out the system behind so that this is easy to remember for me.
Most of the time you want to jump to the start of function, so to a ‘{‘.
Vim tries to make typing easy, and because pressing a key twice is easier than pressing two different keys,
Vim uses ‘[[‘ to jump to the previous ‘{‘ and ‘]]’ for jumping to the next ‘{‘.
The first bracket gives the direction. By repeating the key you say “jump to an opening brace”.

For the case that you want to jump to a closing ‘}’ just use the other key. The first direction key stays the same.
So ‘[]’ jumps to the previous ‘}’ and ‘][‘ goes to the next ‘}’.

Summary:

  • The direction is obvious and easy to remember
  • Jump to a opening brace: repeat key
  • Jump to a closing brace: use the other key

If you are new to Vim, please check out also ‘{‘, ‘}’, ‘(‘, ‘)’, ‘%’, w, b for navigation.
Every Vim user should know these keys.
Use “:help <key>” to get help for it.

Advertisements

0 Responses to “Vim Section Navigation”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





%d bloggers like this: